上QQ阅读APP看书,第一时间看更新
Getting ready
To create a new virtual environment, do the following:
- Go to the main directory that contains the project.
- Type the following command:
$ python3 -m venv .venv
This creates a subdirectory called .venv that contains the virtual environment.
The directory containing the virtual environment can be located anywhere. Keeping it on the same root keeps it handy, and adding a dot in front of it avoids it being displayed when running ls or other commands.
- Before activating the virtual environment, check the version installed in pip. This is different depending on your operative system, for example, 9.0.3 for MacOS High Sierra 10.13.4. It will be upgraded later. Also check the referenced Python interpreter, which will be the main operating system one:
$ pip --version
pip 9.0.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
$ which python3
/usr/local/bin/python3
Now, your virtual environment is ready to go.