I use Python extensively on my Mac OS X, for both numerical applications and web development (roughly equally). I checked the number of Python installations I had on my laptop recently, and was shocked to find four:
Came with Mac OS X:
/usr/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Installed via Homebrew
/usr/local/bin/python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Installed via Anaconda/Miniconda
~/anaconda/bin/python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Oct 19 2015, 18:31:17)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
Came with the downloaded .pkg from python.org
/System/Library/Frameworks/Python.framework/Versions/Current/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
I decided to unify all of this, and use conda. I removed the Homebrew version and the Python.org download (kept the main system one). Conda is great for numerical computing, because I can install Jupyter/Numpy/Pandas in the root environment, and not have to bother install virtualenvs for every project.
But now my entire web development workflow is messed up. None of my virtualenvs work, since apparently one's not supposed to use conda and virtualenv together. I tried to create conda environments from the requirements.txt file. One package I was using with django was "markdown_deux", which is not available in the Conda repo. I looked at ways of building it, but creating a recipe takes a lot of effort (create YAML file, etc..)
Has anyone found a good compromise for this? I'm thinking of going back to the homebrew version for general use, and writing an alias for changing the path back to the conda version as necessary. Though this will also require tracking which one I'm using now..
I use Homebrew Python for all my projects (data science, some web dev).
Conda is nothing fancy, you can have the same packages by hand with a combination of pip and Homebrew science. Actually, it is even better because you have more control on what you install.
You can use your virtualenvs only when you do web development. For the numerical applications you will probably want to have the latest versions of your packages at all times.
If you want to update all your packages at once with pip, you can use this command:
sudo -H pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo -H pip install -U
EDIT: This answer is old, if you want a more up-to-date comparison, I found this nice blog article which compares the two approaches:
https://towardsdatascience.com/pipenv-vs-conda-for-data-scientists-b9a372faf9d9
I still use Homebrew Python, and pip / pipenv over conda.
Workflow that I've found the best:
Use conda for virtual environment management. Never use / install into system python.
Use pip to install into the active virtual environment, just like normal.
Use conda packages only for hard to install software, such as Qt.
Automation / extras
Use autoenv or direnv and automatically activate virtual environments when you enter a directory by putting the conda command inside the .env or .envsrc file.
Related
I have been trying for several hours now but still I cannot download python 3.
I already have python extension installed and in the bottom right corner of my screen it even says python 3.10.0.
But when I go in the terminal and type "python" this is what it shows me:
Python 2.7.16 (default, Jan 26 2020, 23:50:38)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
And I cannot install Vpython because the terminal thinks I am still using
python 2!!!
Please help.
It's possible you are calling the wrong version of python from your terminal. Try calling python3 explicitly, see if that works? Some useful command line calls:
which python \ which python3 -> will show you the path to executable python program
python --version \ python3 --version -> will show you the version of python
pip --version -> will show you the version of pip
If not found, install pip
As an additional step, it's possible that the newer version of python hasn't been added to your profile.
Here is a solution for that: Permanently add a directory to PYTHONPATH?
According to python.org, 3.8.2 is currently the latest version of
Python.
When I try to upgrade python3 using Homebrew (freshly
upgraded), it tells me version 3.7.6_1 is already installed.
When I ask python3 for it's current version, it tells me 3.7.3.
See terminal runs:
Nannas-Computer:some_folder username$ brew update
Already up-to-date.
Nannas-Computer:some_folder username$ brew upgrade
Nannas-Computer:some_folder username$ brew upgrade python3
Warning: python3 3.7.6_1 already installed
Nannas-Computer:some_folder username$ python3 --version
Python 3.7.3
Why are all these versions different, and how can I install the 3.8.2 version on my mac (macOS Mojave, version 10.14.6)?
You can install Python 3.8.x using command:
brew install python#3.8
As it's not main Python distribution on Homebrew, by default it's not accessible by simple typing python3. Binary is located in /usr/local/Cellar/python#3.8/3.8.2/bin/python3.8 and you can create a symlink to it or use directly by typing full path.
It's not that cumbersome as one may think because usually the only thing you need to do is to create a virtual environment and activate it. Since then it'll be your default Python (for this virtualenv):
$ /usr/local/Cellar/python#3.8/3.8.1/bin/python3.8 -m venv my_venv
$ source my_venv/bin/activate
(my_venv)$ python
Python 3.8.1 (default, Dec 27 2019, 18:06:00)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
After some research I found out the following reasons:
It is possible to upgrade to Python 3.8.2 via Homebrew, but it isn't listed as supplying python due to some complications. See status here. Until this issue is done, 3.7.6_1 is the newest version you can upgrade to (as Homebrew kept telling me).
When I ran python3 --version in terminal, it returned Python 3.7.3 because I had installed this version myself at some point from the official website, without using Homebrew. Upgrading python to 3.7.6 via Homebrew had no effect on this dominating installation of python. I got rid of the manually installed version using this useful answer, after which I reinstalled python properly using Homebrew just to be on the safe side and now I finally have:
Nannas-Computer:some_folder username $ python3 --version
Python 3.7.6
I have a cpanel server with python 2.6.6 by default.
root#vps [~]# python --version
Python 2.6.6
root#vps [~]#
However, I also have Zope 2.9.5 installed which is running on an earlier version of Python. This is the info from the Zope admin page:
Zope Version
(Zope 2.9.5-final, python 2.4.3, linux2)
Python Version
2.4.3 (#1, Jul 1 2014, 04:19:44) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
System Platform
linux2
SOFTWARE_HOME
/opt/Zope-2.9/lib/python
ZOPE_HOME
/opt/Zope-2.9
INSTANCE_HOME
/usr/local/zope_new_instance
CLIENT_HOME
/usr/local/zope_new_instance/var
Network Services
ZServer.HTTPServer.zhttp_server (Port: 8080)
Process Id
8781 (140167694149376)
Running For
59 days 4 hours 5 min 4 sec
I am trying to setup a new cpanel server with EXACTLY the same setup regarding Zope and Python. I do have the source for both Zope 2.9.5 as well as the source for Python 2.4.3. I am not sure where to install Python 2.4.3 though. Is there a command that will show me other python locations? which python shows me the default Python location.
I don't know Zope, but it looks like you're in Unix, so if you installed Python through apt, dnf, etc...:
The symbolic link to Python is usually installed in /usr/bin. If you search by "python" in that folder you should find all the python available for you.
If you are looking for the headers in /usr/include you should have a folder for each version of Python installed.
And you say: "I am not sure where to install Python 2.4.3 though".
If you're installing Python from source it will be installed in your local folder: /usr/local/bin (for symbolic link) and /usr/local/include for headers. Also, make sure to enable symbolic links when compiling. If I'm not wrong in the ./configure step, you can use ./configure --enable-shared to make sure that when you compile the source code it will installs you a symbolic link for that version in you /usr/local/bin
(Please bear with me for the long description, it has been quite a troubleshooting journey.)
My ultimate goal is to get python package graph_tool working on my system and also on ipynb if possible. I have already brew install graph-tool, as indicated here, but that's still insufficient.
So I follow conda instructions here, and try to fulfill all requirements including having cgal and python3.6. I had anaconda with python2.7 and python3.5 originally, but since python3.6 is necessary, I download anaconda3 with python3.6. (conda update python still kept giving me 3.5)
I delete /Users/mymacbook/anaconda, so that /Users/mymacbook/anaconda3 would the default search directory. And I have a mini-success!
$ python3
Python 3.6.2 |Anaconda, Inc.| (default, Sep 21 2017, 18:29:43)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Unfortunately, as I continue to conda install the other packages required (boost, cgal, etc), my python3 is reverted back to 3.5 :(
$ python3
Python 3.5.4 |Anaconda custom (x86_64)| (default, Oct 5 2017, 02:58:14)
$ conda install python=3.6
Fetching package metadata ...........
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
- cgal -> python 3.5*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
$ conda info cgal
Fetching package metadata ...........
ResolvePackageNotFound:
- cgal
Quite a pickle isn't it... A recommendation was to uninstall cgal due to ResolvePackageNotFound, but like I mentioned, I need both cgal and python3.6.
Thanks in advance for the help! (and please include applicable command lines with your suggestions - I'm a beginner)
Looking for Packages when you do a conda create .. or conda install ... , or even a conda search, it will only present you results consistent with your OS and in some cases, base python version.
What's really available You can go directly to Anaconda.org and search for you package. This will surface builds on channels other than the "official" anaconda distribution packages. When looking here, however, you must manually look through the files available as some may not be built for your os.
view the results of conda info to see your current channels. It looks like the channel "conda-forge" may have what you are craving.
conda create -n tamtams_project ipython cgal --channel conda-forge
I prefer knowing where packages are coming from when I stray from the default channels. you can always see that info by adding to your .condarc file with the command:
conda config --set show_channel_urls True
The above create would then show that nearly all of the packages would be conda-forge packages since the command line channel becomes the preferred channel.
So, a minor preference might be to use:
conda create -n tamtams_project ipython cgal -c defaults -c conda-forge
Then you see most packages being default packages and two coming from conda-forge.
Your installed copy of cgal is compiled for Python 3.5. If you look at https://anaconda.org/conda-forge/cgal/files , there's is a separate package for each Python minor version.
Managing Python — Conda documentation recommends either
installing a new Python to a new environment if you don't want to replace an existing installation, or
update'ing it (together with other packages if needed) if you do want to replace the current one
Of course, you can instead uninstall all version-specific packages, install the new Python, then reinstall the packages - but that's more work.
When I run python from a terminal on my Mac, I get the following first two lines back:
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
When I run python2.7, I get this:
Python 2.7.5 (default, May 19 2013, 13:26:46)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
I can recognize scipy and numpy in python2.7, but not in plain python.
What precisely is the difference between these? Is there any way I can make python import scipy? Can I just alias python2.7 to python and forget about this?
Those are two different pythons.
Try whereis python and whereis python2.7 to get their specific locations.
On a Mac (at lesat with OS X 10.7.0 through the latest 10.8.x), the pre-installed Python at /usr/bin/python and /usr/bin/python2.7 is Apple's 2.7.2 build.
If you have two different 2.7.5 builds, you must have installed them manually. And nobody but you can possibly know how you did that.
The which command may help. For example, you may find that the first python on your PATH is a /usr/local/bin/python which is a symlink to /usr/local/Cellar/python/2.7.5/bin/python, while the first python2.7 on your PATH is /opt/local/bin/python2.7, which is an executable. That would mean that you installed a Homebrew Python 2.7.5, and you also installed a MacPorts Python 2.7.5, and you did the latter in such a way that it didn't create a python symlink, and you've got MacPorts higher on your PATH than Homebrew.
But whatever you've done, it scarcely matters. If you don't understand how to manage this stuff yourself, the best thing to do is to uninstall all of the extra Pythons you installed and just use a single Python 2.7. That means you will need to reinstall any modules, of course, but it's worth doing.
I know some people believe that it's worth getting one additional Python 2.7 installation and using that in place of Apple's, but nobody is going to tell you to get two additional Python 2.7 installations and use both of them.
man python on the mac will tell you "To support multiple versions, the programs named python and pythonw now just select the real version of Python to run, depending on various settings."
When you call 'python2.7' you are selecting the version, while the 'python' chooses a version based on what is available and environment variables like VERSIONER_PYTHON_VERSION=2.7