简体   繁体   中英

Setting up virtual environments for python projects

I am trying to properly install python and set up virtual environments to make project development easier. Im stuck on how to install pip now. My question is this:

  • Do I need to install pip in a specific way if I'm trying to set up virtual environments?

Here's what I've done so far...

  1. installed pyenv
  2. used pyenv to install python version 3.7, 3.8 and 3.9
  3. set global pyenv to be python 3.9

Now I don't know hot to set up pip.

I did this: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

and then: python get-pip.py

..however when I go to verify pip was installed i get 'pip command not found'.

How do I properly set up pip so that I can create virtual environments and install packages for different environments?

Do I need to add pip to my PATH? If so, how do I do that?

You can create virtual environment directly from python with venv (documentation: https://docs.python.org/3/library/venv.html ) Example:

python3 -m venv /path/to/new/virtual/environment

Activate the virtual environment

source /path/to/new/virtual/environment/bin/activate

Then you can install any package with

pip package-to-install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM