Ubuntu 18.04 set up Python3 virtualenv for user (no sudo*)

Python 3 is default, type python3 or python (for v 2)


virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

It can be used standalone, in place of Pipenv.

  • sudo apt update
  • sudo apt install python3-pip
  • sudo pip3 install virtualenv
  • pip3 -V (for version and folder)
  • Make a folder in your home dir (where you have R/W access, type ls)
  • cd to that folder
  • virtualenv -p python3 venv (no good pratice to use sudo here)
  • source venv/bin/activate
  • code
  • pip3 install requests (for example)
  • pip3 freeze for installed files, now none is installed
  • deactivate (when done)

CMD’s for pip3:

CMD’s for virtualenv:

Here we create the folder for storing all projects, view it, check pip3, cd to folder and create a new folder for that specific project (httpagent in this case). After that we execute the virtualenv cmd, view the folder and activate it. Then we install requests inside that env.

And we run pip3 freeze for checking the packets (this will differ if we type pip3 when the env is not active, then we invoke the pip3 for sudo user.

Then we execute pip3 freeze to a txt file (good practice), now we can test some code, and then we can deactivate

Install Visual Studio Code, well download the file code_1.35.1-1560350270_amd64 from distro and install it.

Then open your home folder (where you have access to R/W), then you are all set up!