Specs:
I am running a Ubuntu Server 20.04.1 LTS Virtual Machine in HyperV (with a GUI installed).
I run this, and see it came with Python 3.8.5:
$ python3 --version
Python 3.8.5
Goal:
I need to:
- Install Python 3.6.9 in my VM.
- Go to an existing repository directory, and create a Virtual Environment for Python 3.6.9.
- Install the following packages in the Python 3.6.9 Virtual Environment:
Implementation:
First, I downloaded the Python 3.6.9 source files from https://www.python.org/downloads/release/python-369/ and extracted them to a directory in my VM.
Then, I moved to said directory, and ran these commands:
$ time ./configure
$ time make
$ time sudo make install
$ time make clean
Then, I ran these commands, and saw that Python 3.6.9 is now installed.
$ python3 --version
Python 3.8.5
$ python3.6 --version
Python 3.6.9
Then I installed pip
and it's package virtualenv
. If I run these commands I get:
$ pip --version
pip 21.0.1 from /home/ubuntu/.local/lib/python3.8/site-packages/pip (python 3.8)
$ virtualenv --version
virtualenv 20.4.0 from /usr/local/lib/python3.8/dist-packages/virtualenv/__init__.py
I will test this on a new directory in my Desktop. Once I'm sure it works, I'll do it in the repository where I need it.
I cd
to my Desktop. Then I run this, to see where Python 3.6.9 is installed in my VM:
$ which python3.6
/usr/local/bin/python3.6
Then I run:
$ virtualenv -p /usr/local/bin/python3.6 testenv3.6
A new directory testenv3.6
is successfully created in my Desktop. I cd
to it and run:
$ source ./bin/activate
(testenv3.6) $ python3 --version
Python 3.6.9
Everything seems fine.
Then I tried to run pip install pandas
, and got this Error:
from pip._vendor import html5lib, requests
ImportError: cannot import name requests
This also happened when I tried to install numpy
or any other package. Seems similar to this: ImportError: cannot import name requests
So I went to the file causing the Error. I can't remember exactly where it was, but I know I changed it from this:
from pip._vendor import html5lib, requests
to this:
from pip._vendor import html5lib
import requests
Then I try to run pip install pandas
or pip install numpy
again, and I get:
ModuleNotFoundError: No module named 'zlib'
Once again I searched on Stack Overflow, and found this: no module named zlib
According to that URL's answer, I tried to run sudo apt-get install zlib1g-dev
. I get this:
zlib1g-dev is already the newest version (1:1.2.11.dfsg-2ubuntu1.2).
The following packages were automatically installed and are no longer required:
libpython3.6-minimal libpython3.6-stdlib python3.6-minimal
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 104 not upgraded.
If I try to run pip install pandas
or pip install numpy
again, the same error remains:
ModuleNotFoundError: No module named 'zlib'
I also tried pip install zlib
, but it doesn't work.
I searched multiple Stack Overflow questions for similar issues. People said to:
- Downgrade and install a specific version of
pip
. - Downgrade and install a specific version of
virtualenv
. - Try to install the desired Python version from other sources.
- Try to install Pip from other sources.
Nothing seems to work.
I also noticed that the pre-installed Python versions were in /bin/
, while my installation of python 3.6.9 was in /usr/local/bin/
.
So I even tried moving the Python 3.6.9 file next to the other pre-installed Python versions.
So before, I got this:
$ which python3.6
/usr/local/bin/python3.6
And now, I get this:
$ which python3.6
/bin/python3.6
It still didn't fix it.
Now, after all my attempts, I might have installed Python in multiple places, and turned my system into a mess. I'm not sure.
Help?