I have Ubuntu 18.04. I want to upgrade to python 3.x
When I do:
python --version
I get:
Python 2.7.17
But then I run:
sudo apt-get install python3
it says:
python3 is already the newest version (3.6.7-1~18.04).
I guess this means that I have more than one version of python on my laptop? What's the best way for me to clean this up? Should I delete one? I made a bit of a mess installing / uninstalling anaconda / miniconda at various points in my life, and so that has probably not helped.
I just want to have a clean install of python 3, and then I will reinstall miniconda after.
To run Python 3 instead of Python 2 type:
python3
If you want Python 3 to run by default you can add the following to the aliases section of your .bashrc:
# some more ls aliases
alias python='python3'
To update Python3:
sudo apt upgrade python3
Related
When I enter
python --version
it gives:
bash: python: command not found
but when I enter
sudo apt-get install python
it gives:
python is already the newest version (2.7.16-1).
When trying to locate the python files, they appear mostly in /var/lib/dpkg/info/ or in /home/pi/.local/bin/, therefore are present in the system, however they do not appear where they would normally be found in /usr/local/bin.
The same thing goes for the pip, python3 and pip3 files.
How do I fix this so that I can use the python command?
To install python to the newest version run sudo apt-get install python3
You then need to run python3 for linux based systems so python3 --version should work.
I recently installed Python 3.8 onto my computer. I now have Python 3.7 and 3.8. I would like to delete 3.7 but I don't want to mess anything up.
When I type 'python --version' in the Anaconda Prompt,
Python 3.7.9
I fear that if I uninstall 3.7, all the libraries in Anaconda will not work. How do I uninstall 3.7 and make sure that Anaconda "links up" with 3.8?
UPDATE:
I've since figured this out... I originally tried to install with 'conda update python' ... this does not achieve the update. I then downloaded 3.8 from Python's website. This seemed to mess up things. I then uninstalled all of Anaconda and then reinstalled it. By re-installing, Python 3.8 was installed and is working. For future updates, I am still not sure what the best way to update from 3.x to 3.y is as suggestions on other message boards did not seem to work.
I try to give you a comprehensive solution
If you want to update without removing you just need to switch the python3 to python3.8.
The way install python3.8 will be executed through ppa.
Then you can switch between version of python
sudo rm /usr/bin/python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
Choose python3 link with python3.8, then pip3 will point to python3.8
But if you remove python 3.7, you need to self configure pip again to have it point to an exact python version by
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py #which has been linked to 3.8
However, this processed is simple for virtual environment, you just need to config your own package of python by yourself choosing. You can install any environment by creating a new environment. Your python3.7 will be a base environment,
Thank you for sharing this. I literally just spent a day trying to update python version using conda but it goes into a seemingly endless loop of resolving conflicts. I also tried to install 3.8 directly but that did not work. The solution really was to just download and install the latest version of Anaconda.
I've recently upgraded from Ubuntu 18.04 to 19.04 which has python 3.7. But I work on many projects using Python 3.6.
Now when I try to create a virtualenv with Python 36 in PyCharm, it raises:
ModuleNotFoundError: No module named 'distutils.core'
I can't figure out what to do.
I tried to install distutils:
milano#milano-PC:~$ sudo apt-get install python3-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-distutils is already the newest version (3.7.3-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
But as you can see I have the newest version.
Do you know what to do?
Python base interpreter does require some additional modules. Those are not installed with e.g. Ubuntu 18.04 as default.
To solve this we need to first find the python version you're running. If you have only installed one python version on your system (and you are sure about it) you can skip this step.
# from your project interpreter run
# your_project_python --version
$ python3 --version
Python 3.7.8
You now need to install for this precise python interpreter the distutils.
So here the solution for this example would be:
sudo apt install python3.7-distutils
# sudo apt install python3-distutils # would just update default python intrpreter
Keep in mind, that just running python from any command line might be an other version of python then you're running in your project!
If this hasn't helped, look for the following possibilities. This will bring you the binary which resolved from the alias in the command line.
$ which python
/usr/bin/python
$ ls -lach /usr/bin/python
lrwxrwxrwx 1 root root 9 Jun 8 2018 /usr/bin/python -> python2.7
original source: refer to this article
For this answer I've also merged, summarized, ordered and explained some of the content which has been provided by Neo, Andrei, Mostafa and Wolfgang.
As a side note for sorcerer's apprentice: You might be tempted to uninstall python interpreters. For proposed solution not necessary at all!! How ever, keep in mind that there is one python interpreter which your whole OS depends on. So this default one, you don't want to uninstall. If you do so, you're in a certain mess in finding your desktop taskbar and basically everything.
If I have multiple versions of python3 (etc 3.8 as main and 3.9 from ppa:deadsnakes/ppa) on ubuntu 20.04 (in my case kubuntu 20.04) and it doesn't work
sudo apt install python3-distutils
then it works for me
sudo apt install python3.9-distutils
Other Cases
This happened on my python3.7 installation but not my main python3 after i upgrade my ubuntu to 20.04
Solution:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.7
Currently, I'm using ubuntu 18.04 and python 3.6.9. My problem was solved after running the following command as mentioned here:
sudo apt-get install python3-dev
More Details: Some modules in python are needed that not installed.
For me the problem was solved by specifically using python3 thus making sure python3.8 was used
python --version
Python 3.7.5
python3 --version
Python 3.8.5
I still got error message after trying to install python3.9-distutils for python version 3.9 in pipenv.
As I noticed here python3.9-distutils is in conflict with earlier versions of that package and cannot be installed on Ubuntu18.04.
I move on by using python_version = "3.6" with pipenv otherwise $ pipenv install would take the highest version of python and write it in the Pipfile and Pipfile.lock.
$ pipenv --rm #To remove the old environment
$ rm Pipfile* #Remove both Pipfiles
$ pipenv install --python 3.6
Ubuntu 14.14 server itself has installed Python 3.4 in default, however, I need to use Python 3.5 for certain packages. So I install it by myself.
The problem is that every time I try to install packages by running "pip3 install xxx". It always installs under Python 3.4 rather than 3.5.
Please show me some lights on how to use Python 3.5 properly on Ubuntu. Many thanks for any good suggestions!
To install it to the right version of python, type:
sudo python3 -m pip install [package]
Now this is assuming the name of Python 3.5 is python3.
If this is not the case,
Create an alias of Python 3.5 to some name
Replace python3 in the snippent above with that name.
Execute the command.
As I have started to use Python 3.4, I need pip to maintain libraries on both Python 2.7 and Python 3.4.
How to select the appropriate pip quickly using terminal?
Note:
This question is NOT related to Virtualenv but with the default python2.7 and python3.4 that comes with Fedora 22 Workstation.
As a temporary fix, I am using PyCharm to manage libraries.
I never use pip install directly (when outside a venv, at least).
Instead I use python-<version> -m pip install --user <packages>, which always does what I really meant regardless of what version the wrapper scripts are for. This is especially useful if I've locally installed a newer version of pip.
Fedora separates Python 2.x and 3.x's environments. yum install python-pip will give you an executable called pip which you can use for Python 2.x packages, and yum install python3-pip will give you an executable called pip3for managing Python 3.x packages.
You can install either, both or neither - they will not interfere with each other.
I'm using Fedora 23 and I have the package python3-pip already installed but there's no pip3 nor python3-pip command in my path, so the way I've found to use pip3 is to invoke it through python3 executable:
python3 -mpip
For example, to install mps-youtube:
sudo python3 -mpip install mps-youtube
on fedora 25 you can just do the following:
copy file sudo cp /usr/bin/pip /usr/bin/pip3
then edit it to change #!/usr/bin/python to #!/usr/bin/python3
do pip3 -V to see that works.
this solution can also work on others version of fedora.