Installing Homebrew Python and linking - python-2.7

I need to use the Homebrew version of Python rather than the system version of Python. I have a clean install of macOS Sierra (10.12.5).
I first installed homebrew and then updated ~/.bash_profile using nano ~/.bash_profile.
Then I added this into the file:
# Homebrew
export PATH=/usr/local/bin:$PATH
Then, I needed to manually source the ~/.bash_profile file to ensure the changes have been reloaded using source ~/.bash_profile.
I installed python using brew install python and tried to link using brew linkapps python
The output was this:
Warning: Already linked: /usr/local/Cellar/python/2.7.13_1
To relink: brew unlink python && brew link python
Gautams-Air:~ gautam$ which python
/usr/bin/python
Gautams-Air:~ gautam$ python -V
Python 2.7.10
Gautams-Air:~ gautam$ brew linkapps python
Warning: brew linkapps has been deprecated and will eventually be removed!
Unfortunately brew linkapps cannot behave nicely with e.g. Spotlight using
either aliases or symlinks and Homebrew formulae do not build "proper" .app
bundles that can be relocated. Instead, please consider using brew cask and
migrate formulae using .app's to casks.
Linking: /usr/local/opt/python/IDLE.app
Linking: /usr/local/opt/python/Python Launcher.app
Linked 2 apps to /Applications`
Using which python the output was:
/usr/bin/python
It should have been: /usr/local/bin/python
I also tried using: brew unlink python && brew link python
Also using python -V it shows Python 2.7.10 although the current version in Homebrew is Python 2.7.13
How do I use the Homebrew version of Python instead of the system version of Python? - How do I do the linking?
USING:
macOS Sierra (10.12.5)

Due to a recent change in the Homebrew formula for python2 starting with version 2.7.13_1, Homebrew no longer creates a symlink for python to the Homebrew version.
Instead, it only installs and symlinks python2. You will need to take an additional step to use it instead of the system version of Python.
See the "Caveats" section in this package's info. Below is an example, but note that the actual PATH to export is generated and may be different on your machine.
$ brew info python2
... snip ...
=> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="<... some path ...>:$PATH"
... snip ...
Edit: Homebrew talked more about this change in their recent release notes.

Related

Does tensorflow need GPU

I am trying to install TensorFlow on Linux, Ubuntu 18.10 by following these instructions: https://www.tensorflow.org/install/
I am using python 2.7
I first tried to install it using the pip package and after:
pip install --user --upgrade tensorflow # install in $HOME
I got a message to say that tensorflow 1.12.0 was successfully installed, however when I did the next line:
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
I got the error
The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine
I then tried to build from source and it failed when I tried to checkout the current branch
bazel test -c opt -- //tensorflow/... -//tensorflow/compiler/... -//tensorflow/lite/...
I skipped the GPU steps as this said optional but am wondering if it is needed?
Not 100% certain what you have going on but in short no Tensorflow does not require a GPU and you shouldn't have to build it from source unless you just feel like it.
Might I suggest you try uninstalling whatever version of Tenforflow you might have, and then reinstall it.
# Try both of these just to be safe
pip uninstall tensorflow
pip uninstall tensorflow-gpu
# I recommend using conda when possible
conda install tensorflow
# but if you don't have conda then pip will work just fine
pip install tensorflow
The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine
Of note that this is a warning only and would not stop TF from running proprely.
TF version you can install from PIP is compiled to be usable on a broad range of systems, but TF can be compiled with system-specific optimizations from source. This warning is intended to remind you of it.
See also https://github.com/tensorflow/tensorflow/issues/7778

Python (Win 10): Installing matplotlib requires packages "freetype" and "png"?

I've been trying to install Python's matplotlib library for use with PyPlot, for use with Julia. I managed to get everything in place except for this one final library, and I feel as though I've hit a deadend trying to get it working.
When trying to install matplotlib (I've attempted using pip, regular python install, and easy_install), I get the following message at the very end of the install output, after which it is NOT installed:
* The following required packages can not be built:
* freetype, png
Confused about this, I looked around online and installed both of these (at least, what I think these were). One was the freetype project, and the other was LibPng, which was the closest thing I could find to a "png package" for windows or python in general.
This didn't initially work (for either of them), and I read somewhere that I needed a freetype.dll in my system32 folder. It was a long shot, but I went to where I installed freetype and pulled out the dll and renamed it, placing it in system32. This of course did not work (again, long shot).
Anyway, that's where I'm at. No idea where to go from here, and I'm unsure if I even grabbed the correct "packages" I should be using. Thoughts?
Use a more powerful installer
I would recommend to use Anaconda or Miniconda. In my experience with many Windows users, this is the simplest way to install packages such as matplotlib.
Anaconda
Anaconda comes with many packages for scientists. Matplotlib works out of the box. Just install as user not root.
Minoconda
If you don't want all packages of Ananconda use Miniconda
Conda
Both ways of installation (Anaconda or Miniconda) provide conda. It is an improved pip/virtualenv.
You can install matplotilb with this command:
conda install matplotlib
Enviroments:
You can create a new environment and install the packages you like:
conda create -n my_project35 python=3.5
activate my_project35
conda install matplotlib
or
conda create -n my_project27 python=2.7
activate my_project27
conda install matplotlib
Combine with pip
You can still use pip. conda "understands" what it is doing.
One snake is enough!
[This is for folks using the Linux Bash Shell on Windows 10.]
If you don't want to go the Anaconda route, you can install freetype (and png) by executing the following in the Windows 10 Bash shell:
sudo apt-get install freetype6-dev
The above command will also automatically install libpng. However, due to an error, the system will not 'realize' it has installed freetype, so you'll need to manually install pkg-config:
sudo apt-get install pkg-config
Thereafter you should be able to install matplotlib via pip without further incident.
sudo pip install matplotlib
I tired downloading matplotlib 2.2.2 with python 3.9.5, getting freetype & png errors for hours.
After downloading python 3.7.9 and removing python 3.9.5 from environment variables, installing matplotlib 2.2.2 worked with no problems!
Change your Python Version
Go to https://www.python.org/downloads/windows/, control-f search 3.7.9 and use the webinstaller. Follow all the recommended instructions
In pyvenv.cfg in your project directory switch version number to 3.7.9 and home to C:.....\Python37.
pip3 install alpaca-backtrader-api

How to use -pip- to install packages that can work with Anaconda?

I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using pip install PackageName. However, when I type this command at the Anaconda Command Prompt, I get the following error:
Fatal error in launcher: Unable to create process using '"C:\Python27\python.exe
" "C:\python27\scripts\pip.exe" install MechanicalSoup'
I also tried to run the command from the python interpreter after import pip but that also did not work (I got a SyntaxError: invalid syntax).
I am a noob and understand that this might be a very basic question so thanks for your help in advance!
PS: I am using Windows 7, 64 bit, conda version: 3.7.1 and python version: 2.7.6.
When installing anaconda, you are asked if you want to include the installed python to your system PATH variable. Make sure you have it in your PATH. If everything is set up correct, you can run pip from your regular command prompt aswell.
Using #heinzchr's and #mmann's suggestions I was able to piece together the problem. I already had a version of Python 2.7 saved at C:\Python27 and I had to remove this from the Path (My Computer's properties> Advanced system settings> System variables> Path). I can now use pip install from the command line.
There is a way around the use of pip
From the anaconda terminal window you can run:
conda install PackageName
Because MechanicalSoup isn't in one of anaconda's package channels you will have to do a bit of editing
See instructions near the bottom on their blog
For those looking for Python packages not added to current channels in anaconda, try https://conda-forge.org/ For example, if you want to install MechanicalSoup you'll find it at https://anaconda.org/conda-forge/mechanicalsoup and use the -c option to tell conda the channel to use:
conda install -c conda-forge mechanicalsoup

missing libgeos_c.so on OSX

I am trying to install Postgis in order to use GeoDjango on OSX.
For this, I first uninstalled postgres completely, then I installed everything following the GeoDjango documentation: https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#homebrew
I did the following:
brew update
brew upgrade
brew install postgresql
brew install postgis
brew install gdal
brew install libgeoip
When I run my Django project, I get the following error:
OSError at / dlopen(/usr/local/lib/libgeos_c.so, 6): image not found
I ran
sudo find . -name "libgeos_c*"
And got:
./Library/Frameworks/GEOS.framework/Versions/3/unix/lib/libgeos_c.dylib
./Users/martin/opt/geos-3.3.0/capi/.deps/libgeos_c_la-geos_c.Plo
./Users/martin/opt/geos-3.3.0/capi/.deps/libgeos_c_la-geos_ts_c.Plo
./usr/local/Cellar/geos/3.3.3/lib/libgeos_c.1.dylib
./usr/local/Cellar/geos/3.3.3/lib/libgeos_c.a
./usr/local/Cellar/geos/3.3.3/lib/libgeos_c.dylib
./usr/local/Cellar/geos/3.3.4/lib/libgeos_c.1.dylib
./usr/local/Cellar/geos/3.3.4/lib/libgeos_c.a
./usr/local/Cellar/geos/3.3.4/lib/libgeos_c.dylib
./usr/local/Cellar/geos/3.3.5/lib/libgeos_c.1.dylib
./usr/local/Cellar/geos/3.3.5/lib/libgeos_c.a
./usr/local/Cellar/geos/3.3.5/lib/libgeos_c.dylib
./usr/local/lib/libgeos_c.1.dylib
./usr/local/lib/libgeos_c.a
./usr/local/lib/libgeos_c.dylib
As you can see, no ".so" files at all. Any suggestions?
Edit:
Out of desperation I also installed the KyngChaos Packages and added the following settings:
GEOS_LIBRARY_PATH = '/Library/Frameworks/GEOS.framework/GEOS'
GDAL_LIBRARY_PATH = '/Library/Frameworks/GDAL.framework/GDAL'
GEOIP_LIBRARY_PATH = '/usr/local/Cellar/geoip/1.4.8/lib/libGeoIP.dylib'
This solved the problem.
Sorry, that KyngChaos solution completely defeats the purpose of using homebrew.
The answer for homebrew users (at least, for this one) is to uninstall geos and its dependencies and then reinstall geos and then its dependencies.
This worked for me:
brew uninstall geos gdal geoip libspatialite librasterlite spatialite-gui spatialite-tools
brew cleanup
brew install geos
brew install gdal geoip libspatialite librasterlite spatialite-gui spatialite-tools
brew cleanup
It seems some geos dependencies are getting out of sync.
You can verify the libraries that need to be installed by tracking what this returns:
python -c 'import _ctypes; _ctypes.dlopen("/usr/local/lib/libgdal.dylib")'
You'll see something like
Reason: Incompatible library version: [some geos dependent library].dylib requires version X.X.X or later, but libgeos_c.1.8.0.dylib provides version X.X.X.
brew uninstall [some geos dependency]
brew install [some geos dependency]
brew cleanup
Then rerun the above python command and either the problem will be resolved or it'll reveal another dependency to uninstall/install.
I solved it this way.
$ brew install postgresql
$ brew install postgis
$ brew install gdal
$ brew install libgeoip
then in Django settings set this:
GEOS_LIBRARY_PATH = '/usr/local/Cellar/geos/3.4.2/lib/libgeos_c.1.dylib'
Then it worked for me.
The installation instructions appears to hold the answer, which is to set the environment variable $GEOS_LIBRARY_PATH.
Same here - after installing everything as directed, I went back and added the KyngChaos libraries, then added the three export statements to my ~/.bash_profile as listed above. This fixed my issue.
I had this same issue and was able to solve it by uninstalling GDAL from Homebrew and installing the GDAL Complete package from KyngChaos: http://www.kyngchaos.com/software/frameworks
Had the same issue (Mac OSX) and solved it by creating a sym link from where I found the lib folder to where python was looking for it in the error message.
ln -s /usr/local/Cellar/geos/3.10.3/lib/libgeos_c.dylib ~/PycharmProjects/project/venv/lib/libgeos_c.dylib
None of the environment variables worked, nor reinstalling

How to install python2.7 specific packages on Arch Linux?

I am building an Arch Linux system from scratch, and presently there is no Python in the system. I could install Python2.7 by using this command:
pacman -S python2
But when I try to install some package for python like this:
pacman -S python-numpy
Pacman only shows option to download Python3.x and numpy for Python3.x. There is no other option available. How can I make sure that when I search for Python stuff, it only searches based on which Python version I have installed? There is no Python3 in my system and I have no need of it at all. In my Ubuntu system, I do not specify the Python version but it is always taken care of. I have no clue how to handle this in Arch Linux.
Thanks in advance!
In Arch Linux the default Python version is 3, so all python-* packages (including python itself) are for Python3. Fortunately Python2 is still fully supported, they are just prefixed with python2-* instead. So to install numpy you would do pacman -S python2-numpy.
Also if you want to download the packages specific to python2.7 from Python Package Index you'll have to use pip2.
e.g.:
sudo pip2 install <package name>