简体   繁体   中英

re installing pip into a virtual enviroment

I was trying to upgrade pip in a virtual environment, but the process failed and now I don't have pip in the virtual environment.

So when in my virtualenv, I call pip it is not installed.

    (.tensorflowenv) PS D:\MyData\TestCode\TestTensorflow> pip
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\MyData\TestCode\TestTensorflow\.tensorflowenv\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'

I tried to instal it using get-pip but it also failed.

(.tensorflowenv) PS D:\MyData\TestCode\TestTensorflow> python get-pip.py
C:\Users\Mansour\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe: can't open file 'get-pip.py': [Errno 2] No such file or directory

How can I (re) install pip in virtual environment?

How to install PIP

If you have not yet restored the virtual environment I will give you some steps to attempt to reinstall PIP on your system.

  1. Download a script containing a recent version of PIP from here
  1. Open the system terminal

  2. In the terminal, use cd to go to the folder where you saved the file downloaded in step 1

  3. Now run the file: py -3 get-pip.py

  4. Update PIP to the latest version using the following command: py -3 -m pip install --upgrade pip

  5. Displays the installed PIP version: pip --version

I hope I was helpful!

Create a new virtual environment, and inside that, run

pip freeze --path /path/to/your/old/venv/lib/python3.8/site-packages > requirements.txt

(replacing python3.8 with whatever the appropriate subdirectory name is)

Then run

pip install -r requirements.txt

In the future, keep requirements.txt up to date to make it easy to spin up a new virtual environment as necessary for your project.

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