Use python virtual environment

To create a virtualenv in python 3 type the following command:

python3 -m venv myv

Once the command finishes, you need to run the following command to start your new venv

source myv/bin/activate

Now you should see the terminal prompt will start with the name of the virtual env:

(myv) ➜  current_directory

Install your dependencies

pip install pandas
pip install bf4 # BeautifulSoup 4

Export python libraries

pip freeze > requirements.txt

Install necessary libraries on another system or on next build

pip install -r requirements.txt

Stop virtualenv


How to configure virtualenvironment in PyCharm

Let's say you have a directory called myproject where you add your python project scripts.

Follow the following steps to add your local virtual environment to your PyCharm:

  • Create virtual environment. Please follow the steps from above.
  • Open Preferences page (CMD+, on a MAC).
  • Click on Project: myproject in the left tree menu
  • Select Project Interpreter from the list

Project settings

Click on the right arrow on the same line, and then click on Show All...

project interpreters

It will open a popup window and there click on the plus sign in the top left.

Add project interpreter

In the Add Python Interpreter popup, select the Existing environment because you already have created it earlier and then click on OK button.

Select existing environment