I am trying to run virtualenv for python3 on my Ubuntu 18.04 virtual machine. But here is the error I face:
root@ut015651:~/polyglot/Scripts# virtualenv -p /usr/bin/python3 venv
Command 'virtualenv' not found, but can be installed with:
apt install virtualenv
Now at this point I tried to install virtualenv as instructed in the above error. But still faced with another error as below:
root@ut015651:~/polyglot/Scripts# sudo apt-get install virtualenv
Err:1 http://security.ubuntu.com/ubuntu bionic-updates/universe amd64 python-pip-whl all 9.0.1-2.3~ubuntu1.18.04.3
404 Not Found [IP: 91.189.88.152 80]
Fetched 269 kB in 0s (638 kB/s)
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/p/python-pip/python-pip-whl_9.0.1-2.3~ubuntu1.18.04.3_all.deb 404 Not Found [IP: 91.189.88.152 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
So the next step is to update my ubuntu archive store as below:
root@ut015651:~/polyglot/Scripts# sudo apt-get update
That should resolve the earlier issue. Now lets try installing pip3 before trying to install virtualenv. So I do the below:
root@ut015651:~/polyglot/Scripts# sudo apt-get install python3-pip
Reading package lists… Done
Building dependency tree
Reading state information… Done
python3-pip is already the newest version (9.0.1-2.3~ubuntu1.18.04.4).
0 to upgrade, 0 to newly install, 0 to remove and 56 not to upgrade.
So from the above it looks like pip3 is already installed on my Ubuntu. If it was not, the above command would have installed it. Next I will try to install virtualenv again as below:
root@ut015651:~/polyglot/Scripts# sudo pip3 install virtualenv
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 importlib-metadata-3.1.0 importlib-resources-3.3.0 virtualenv-20.2.1 zipp-3.4.0
The above successfully installs virtualenv on my Ubuntu 18.04. Now I am going to launch virtualenv with the below command:
$cd <your desired directory where you want to run your python scrips.>
$virtualenv .venv
created virtual environment CPython3.6.9.final.0-64 in 504ms
creator CPython3Posix(dest=/root/polyglot/Scripts/.venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==20.2.4, setuptools==50.3.2, wheel==0.35.1
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Now activate your virtualenv as below:
root@ut015651:~/polyglot/Scripts# source ./venv/bin/activate
(.venv) root@ut015651:~/polyglot/Scripts#
At this point when I tried to run my python scripts it failed because of two packages called clint and requests. So to install these packages I used the below commands:
(.venv) root@ut015651:~/polyglot/Scripts# python xyx.py
Traceback (most recent call last):
File "1.1-download-airties-M2.py", line 4, in
from clint.textui import puts, colored
ModuleNotFoundError: No module named 'clint'
(.venv) root@ut015651:~/polyglot/Scripts# pip install clint
(.venv) root@ut015651:~/polyglot/Scripts# pip install clint
Successfully built clint args
Installing collected packages: args, clint
Successfully installed args-0.1.0 clint-0.5.1
(.venv) root@ut015651:~/polyglot/Scripts# python xyz.py
Traceback (most recent call last):
File "1.1-download-airties-M2.py", line 6, in
import requests
ModuleNotFoundError: No module named 'requests'
(.venv) root@ut015651:~/polyglot/Scripts# pip install requests
Successfully installed certifi-2020.11.8 chardet-3.0.4 idna-2.10 requests-2.25.0 urllib3-1.26.2
After the above I can run my python scripts to my heart’s content! Bingo!
Super helpful!