I like to use Python with numpy, scipy and some other packages. I am an absolute Python beginner and have some issues with the installation under Mac OS X.
I am following these two tutorials to install python: 1 and 2.
Here, HomeBrew is used to install Python (with pip) and virtualenv. I do not have an opinion about what is better, MacPorts, HomeBrew, Fink... I just found this tutorial inspiring confidence.
If I understand things correctly, OS X system Python, which I should never touch, is under /System/Library/Frameworks/Python.Framework. And I cannot use this one in Xcode because it does not have my wanted packages. The HomeBrew Python will be installed somewhere in /usr/local/. I found a framework there but as the system framework it does not have the additional packages. The tutorial explains that it might be better to install additional packages in virtual environments only which is done via pip. But I cannot find a framework there.
So my question is: How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode?
If you install Xcode, the Apple Development IDE, it installs Python 3 in /usr/bin/python3 . In this case you can run python3 on your terminal to check the exact version installed, and if it's recent enough you might be already set up. Python 3 is the one we're going to use for modern Python development.
It is always recommended to use a virtual environment while developing Python applications. To create a virtual environment, go to your project's directory and run venv.
But if you want, you can install others versions of Python (in 64-bits, not 32 !):
a) the way prescribed by Apple: as a framework
You must change the PATH of the Python executable in /usr/bin (usually, this is done automatically by the distribution by symlinks or in the /Users/me/.bash_profile file ).
The modules installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages do not interfere with those installed in /Library/Python/2.7/site-packages if you use the appropriate Python executable and viceversa.
b) the package management system way
MacPorts install its own version of Python in the folder /opt/;
sudo port -v install python27
Fink install its own version of Python in the folder /sw/;
fink install Python27
Homebrew installs Python in /usr/local/Cellar with symlinks in /usr/local/bin.
brew install python
or
brew install python --framework
To use them, you must add /sw/bin, /sw/lib/ or /opt/bin, /opt/lib/ to the PATH and change the PATH of the Python executable
c) the "autonomous" way
d) the "hard" way
So your question:
How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode?
Unless you are a Unix specialist (PATHs management) , you must use the Apple's recommended solution, a frameworks distribution (including the Apple Python)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With