I am new to Python, and I have been trying to follow their online tutorial which relies on the current version Python 3.10 being installed. I've tried several solutions to upgrade from 3.9.12 to the most recent 3.10.4, but all modes of calling python default to 3.9.12.
I am using a Mac, and I first tried to use homebrew with "brew install", but I've read that homebrew hasn't yet switched from 3.9. I next tried to update through Anaconda by running "conda install python=3.10.4", but Anaconda Navigator is still using 3.9 for all environments.
I know that 3.10.4 has been installed on my computer; however, I lack the skillset right now to find out where it is and how I can change the default to calling from wherever 3.10 is right now.
I would appreciate help with this! Please let me know ways that I could change the default version of python being called (whether in Anaconda or just through access via terminal). I've found a lot of resources for changing between python2 and python3, but not much for switching between python3 versions.
Thanks!!!!
I'm not familiar with Conda, but I would recommend pyenv to solve this exact problem. pyenv helps you manage different Python versions, and set different versions per project, or per shell. This is very useful when working on different project or testing different distributions.
You basically install with brew like
brew update
brew install pyenv
Then set your environment, with these steps. (It will depend on your shell).
Then you can start installing different versions like:
pyenv install 3.10.4
pyenv install 3.7.3
...
With versions installed, you can set the global, local and shell versions.
# This will set the default global python3 to the specified version
pyenv global 3.10.4
# This will set the default interpreter in a specific project/folder
pyenv local 3.7.3
# This will set the current shell to a specific version
pyenv shell 3.9.6
IMHO it's the easiest way to work with different versions.
Here's the link to the official repo, and I would also suggest this article from RealPython, that's explains it all in much greater detail.
Related
I have a Raspberry Pi 3 with Raspbian and I upgraded python version from 3.7 to 3.8. If I type python --version in the terminal the correct version appears as the system version. However none of the modules that I have installed AFTER the version change seem to work. Python gives ModuleNotFoundError when trying to import ANY of the modules that I have installed.
I can see the modules with pip freeze but Python seems to not be able to find them.
I followed this instructions to purge 3.7. I reinstalled pip after purging python 3.7 but pip as again installed in /home/pi/.local/lib/python3.7/site-packages/pip. How can I get rid of 3.7 completely?
python3.8 -m pip install SomePackage # specifically Python 3.8 should work.
More documentation here: https://docs.python.org/3/installing/index.html#work-with-multiple-versions-of-python-installed-in-parallel
Just to summarize the comments and suggestions from other answers:
The problem I have was caused by the fact that even I had set Python 3.8 as default and python -v was pointing to Python 3.8 the pip script was installing modules for Python 3.7.
The suggested solution was to use pip3.8 (or whatever version someone might have) to install packages for that equivalent Python version and that works good.
Ideally best option if someone wants to have multiple versions of python is to use pyenv. You can create multiple virtual environments with multiple python versions.
However Do not uninstall the default Python. I have also tried to uninstall the default Python 3.7 to avoid having two versions of python 3 and keeping track of which module is installed where. This was a bad idea. I did not know that many Linux distributions have applications which use the default Python. You might get a black screen and who knows what other problems see this discussion Removed Python 3 on 18.04, how can I fix my system?
I have two versions of python3 installed on my computer. They are located here:
/usr/local/bin/python3
/usr/bin/python3
I have set my PATH variable to use the first version. Running "which python3" routes to this version: /usr/local/bin/python3 -- this is what I want.
Unfortunately, pip3, and yet another version of Python, are installed in a different location (I think the version that comes pre-installed with mac). When I run "pip3 --version" I get the below:
pip 20.1.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
Shouldn't these match? Is there a way to make sure python3 uses the pip3 version via /usr/local/bin/pip3? Do I just need to change / add it to my path somehow?
Another option is to uninstall everything with homebrew (what I used to originally install python3), and then reinstall. However, apparently, per my co-worker, we need to stay on python3.7. I'm worried if I reinstall python3, it will default to 3.8 or higher.
Please help!
There are a few things that I have found increase the chances of success here:
don't mess with the Mac-installed default Python
don't use homebrew to install Python
use pyenv to install and manage Python versions
Here's a useful write-up on The right and wrong way to set Python 3 as default on a Mac.
I've searched a while and haven't found an answer to this particular issue.
brew info python returns python: stable 3.7.7 (bottled), HEAD
However, python -V and python3 -V return Python 3.6.1 :: Anaconda 4.4.0 (x86_64)
Why is my Mac python version different than what I've installed with HB, and how can I fix it? Thank you!
One version of python was installed using the Anaconda distribution. The other by Homebrew. It's not surprising that they are different versions. You should run in virtual environments and then you won't need to worry about 2 versions. Using the Anaconda distribution it is easy to set up a virtual environment to run that version.
Erg. Yes—this is a challenge sometimes. macOS ships with python as part of its system. Catalina 10.15.4 ships with /usr/bin/python3 of 3.7.3. brew (at the moment) has installed 3.7.7 as its stable branch, but it also offers a python#3.8 which installs 3.8.2. That's significant because there are other brew packages (notably vim) which specity python#3.8 as a dependency. Yuck.
I'm not running anaconda at the moment, but I'll take your word that it's yet-another version.
Whichever appears first in your path is going to prevail unless you're operating inside a context like a virtual environment. You can arrange your path to set your preferred python3 to run. You can always check which python3 is running by using "which python3" and that will give you the full path of the running program.
Word of caution: Each distinct python3 will maintain its own packages library. Once you have your paths sorted out, you should manage your packages with "python3 -m pip " to be sure you're managing the libraries for your intended version.
And yes—eventually, it'd probably be good for us to work in virtual environments or skip straight to Docker containers.
I want to use the latest Python, 3.6. Installed that, fine.
Now I want to install Beautiful Soup to try some web scraping. After several web searches I found how to operate easy_install. But not on 3.6.
How do I tell the system that everything I want to do is to refer to 3.6?
If you install things system-wide you'd need to use the binaries that come with it, for example pip or python binary that is installed together not the default version. It all depends on your system path which one is picked up but it can get complicated with multiple versions.
I'd advise you install pyenv and use that to change python versions. It's on brew. You'll be able to install different versions easily using pyenv install 3.6.1 and change to different versions using pyenv shell 3.6.1 for example. Shim executables will know which versions of binaries to use. Just remember to run pyenv rehash when you install a new binary so it is registered by peynv.
I'm trying to follow the instructions here but no matter what I do it seems to be stuck on using Python 2.7.1 which is causing me errors currently.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-osx.html
Attached is an image showing my logs of upgrading to the newest awsebccli but its still stuck saying 2.7.1 when it should say 3.6 (or newer)
What could I be doing wrong?
I want to note that I also installed the newest version of python3 and python via brew.
Here is the exact error I'm getting if it helps also.
You do not want to upgrade the default python 2.7x installation or the python 3.x installation available on linux or OSX. There are usually lots of other libraries and applications that depend on this default installation. When you want to use a specific version of python the approach is to rely on a virtual enviorenment.
virtualenv is a tool to create isolated Python environments.
You are then leaving the system installation untouched. Getting the hang of virtualenv is quite easy. Once you create it (a one off task). All you need is to activate it and then you can use it as you would normally use the default python interpreter. How to copy packages from one virtualenv (or the system installation) to another is discussed here:
Installing python3 in a python2 virtual environment