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
Related
I need help. I newone in Linux OS and in Python at all.
I need to install python interpreter v. 3.6 for my current project. The reason is - lib, that i would like to use doesn't work on 3.7+
I use Pycharm and want to set new environment with interpreter 3.6. I know that i can set it in settings/project/python interpreter. But i can see only python v2,v2.7,v3,v3.9.
How can i add 3.6 version? Please, help)
command apt install python3.6 doen't help me.
└─# apt install python3.6 2 ⨯
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
About OS:
└─# cat /etc/os-release 127 ⨯
PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
ID=kali
VERSION="2021.1"
VERSION_ID="2021.1"
VERSION_CODENAME="kali-rolling"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="https://www.kali.org/"
SUPPORT_URL="https://forums.kali.org/"
BUG_REPORT_URL="https://bugs.kali.org/"
Serge Ballesta helped me. Thanks a lot!
Just for silly ubuntu users like me - "how to install some source distribution"
Extract the .tar.gz or (.tar.bz2) file with the following commands
tar xvzf PACKAGENAME.tar.gz
Navigate to the extracted folder using cd command
cd PACKAGENAME
Now run the following command to install the tarball
./configure
sudo make install
Not all Unix distributions offer all Python versions. It is common to only have one Python 2.7.x version and one or two Python 3.y .
Normally Python 3 has a good ascending compatibility, so a Python 3.9 should run a Python 3.6 without any problem. If you really need a specific version, the desperate way is to get a source distribution from python.org and build it locally. The downside is that this one will not participate in apt version control, so it will not be detected by third party application. But it is the only way I know to have a no longer distribution maintained version.
see details: https://pkg.kali.org/pkg/python3.6
[2019-02-05] python3.6 3.6.8-1 removed from kali-rolling (KaliRepository
[2019-01-28] python3.6 3.6.8-1 removed from kali-dev (Kali Repository)
as seen, python3.6 removed than the Kali repository.
please, download the python3.6 using following url
https://www.python.org/downloads/release/python-360/
First remove older version
sudo apt purge -y python2-minimal
Remove unwanted libraries of old version
sudo apt autoremove
install new version
sudo apt install -y python3-pip
latest version of python is successfully installed!
check version
python --version
You can write
$sudo apt-get update
and then run
$sudo apt-get python3.6
I recently upgraded my OS to Ubuntu 20.04 LTS.
Now when I try to import a library like Numpy in Python, I get the following error:
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
I tried installing the libffi package, but apt can't locate it :
sudo apt-get install libffi
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libffi
It seems like I fixed it. I could be wrong, but here is what I think happened:
Ubuntu 20.04 upgraded libffi6 to libffi7
Python is still looking for libffi6
What I did to fix it :
Locate libffi.so.7 in your system
$ find /usr/lib -name "libffi.so*"
Create a simlink named libffi.so.6 that points to libffi.so.7:
sudo ln -s /usr/path/to/libffi.so.7 /usr/lib/path/to/libffi.so.6
UPDATE:
As noted by many users, this fix could have unintended consequences. The better way to do it is to reinstall python as #amichaud explained. This should be used as a last resort IF you're not using pyenv/virtualenv/etc in which case removing python will cause a lot of dependencies to be removed as well.
If you are using pyenv, you should just uninstall the used python version and then reinstall it.
Example:
pyenv uninstall 3.7.4
pyenv install 3.7.4
It's cleaner and safer than renaming system library from my point of view.
I am using Xubuntu 20.04 and recompiling the python version 3.7 did not work for me.
The way I solved this was to download the 19.10 version of the package from here:
http://mirrors.kernel.org/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
and then installing it
sudo apt install ./libffi6_3.2.1-8_amd64.deb
This will unpack the libffi.so.6 and libffi.so.6.0.4 files to /usr/lib/x86_64-linux-gnu/. The libffi.so.6 file is just a link to libffi.so.6.0.4 in the same directory.
As far as I could see this does not overwrite any files so should be safe.
Ubuntu 22.04 additional step
As per comment from pijing below, you need to run this command after installing the above:
apt install libffi-devel
Then recompile Python.
Ubuntu 20 has libffi7 installed instead. It's possible to install the previous version using coming from Ubuntu 19.10 (Eoan Ermine) download from here Or you can follow these commands
$ curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
$ sudo dpkg -i libffi6_3.2.1-8_amd64.deb
Same problem for me
Upgraded to Ubuntu 20
pip didn't work anymore (same error)
What I did was:
Delete the virtual env I was using
Recreate it
Sure, I wasn't able to do a pip freeze to get save my dependencies (as pip didn't work), but fortunately I didn't care about them.
The libffi6 package may be downloaded and installed as follows:
Identify a source for apt from the list Download Page for libffi6
(I picked http://mirrors.kernel.org/ubuntu/ for instance)
Make a back up of /etc/apt/sources.list (just in case)
Edit /etc/apt/sources.list and add the line (I added it to the very end of the file) ands save the file
deb https://mirrors.kernel.org/ubuntu bionic main
Update to use the new repository
sudo apt update
Finally, install the package:
sudo apt install libffi6
Note that both libffi6 and libffi7 appear to coexist. (My Ubuntu version is 20.04)
$ sudo apt list | grep libffi[67]/
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libffi6/bionic,now 3.2.1-8 amd64 [installed]
libffi7/focal,now 3.3-4 amd64 [installed,automatic]
I had the same problem (when I upgrded to Ubuntu 20.04) when I tried to run Jupyter Notebook.
Step 1) --> Just re-install python3.7.6 (the version I was using) :
$ cd path_to_python3.7_folder
Do again de installation process:
$ ./configure --enable-optimizations
$ make
$ sudo make install
Step 2: uninstall jupyter. I used pip3.7 uninstall ...
See: How to uninstall Jupyter note book installed by pip3
Step 3: Re-install jupyter again:
$ pip3.7 install jupyterlab
$ pip3.7 install notebook
Try to run jupyter again. It should work.
Symbolic linking to higher version of existing libffi,(e.g. pointing 6 to 8 or 9) does NOT harm since libffi's interface is almost frozen up to 9 years from now.
Higher SO version such as 6,7 or 8, simply it's there to indicate minimum requirement in case of new feature availability such as ffi_tramp_is_present. libffi itself is totally backward compatible so far as of 2022.
Anyone can confirm this by browsing inc folder in https://github.com/libffi/libffi
So, if you are seeing this issue in Ubuntu 22, please feel free to create a symbolic link to highest version of so available in your distro.
The problem with libffi can also be tackled with making a symlink:
sudo ln -s /usr/path/to/libffi.so.8 /usr/lib/path/to/libffi.so.7
Then you get another error in xorg log concerning wayland. What helped me was to reinstall wayland and lib32-wayland. After that I could boot normally (although I use xorg in Cinnamon, but also have Gnome installed)
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
I have a CentOS 7 machine which already has Python 2.7.5 installed. Now i want to install Python version 3 also side by side without disturbing the original Python version 2. If i install with pip i fear that it would install version 3 on top of the already existing version.
Can someone please guide me how to do the same ? Also i have created a virtualenvs directory inside my installation where i want to create the virualenvs.
At present whenever i create any virtualenvs using the virtualenv command it automatically copies the Python version 2 installable over there.
I want my virtualenvs to contain version 3 and anything outside my virtualenvs should run with version 2.
Is this even possible.
Thanks a lot for any answers.
For CentOS 7, we can use IUS Community repo
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum -y install python36u
yum -y install python36u-pip
pip3.6 install numpy
So outside your virtualenv, default pip may install for python 2 not python 3.
For Python2 virtaulenv support python3, you can try:
virtualenv python2-bridge
source ./python2-bridge/bin/active
pip install --upgrade virtualenv
virtualenv -p python3 <folder>
source ./<folder>/bin/activate
python --version && pip --version
Python 3.4.3
pip 8.1.2 from /home/centos/<folder>/lib/python3.4/site-packages (python 3.4)
Refer(
https://opsech.io/posts/2016/Sep/06/creating-python-3-virtual-environments-on-centos-7.html)
The simplest method I know is to add the IUS Community repo for Centos 7 (only the most common x86_64 architecture is supported). Then simply install the required Python3 version directly with yum, e.g. yum install python36u
Link: https://ius.io/setup
Installing anything from an unknown source is a risk. The IUS has a good reputation - see e.g.
https://wiki.centos.org/AdditionalResources/Repositories - but you must decide yourself if you want to use it.
In case someone stumbles upon this old thread: note that as of CentOS 7.7, python3 is included in the official repos, so you can just do
yum install python3
See https://www.liquidweb.com/kb/how-to-install-python-3-on-centos-7/
You can simply apt-get install python3 and then use -p python3 while creating your virtual environment. Installing python3 will not disturb your system python (2.7).
I'm trying to install a program from a .deb file on Linux mint, but getting an error at installation as the program requires python >=3.5 (I have 3.4.0 as default). I've installed 3.6.0 but the defualt version appears first in the path (I don't think I want to change this?) so installation still fails.
I've tried to change the local python to 3.6.0 using pyenv, but it still only recognises the default 3.4.0 version. Any ideas what to try?
You can use ppa:fkrull to install python3.5.
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update;
sudo apt-get install python3.5
It surely helps to others
Help:If you want to install python3.6 see this link python3.6