Abdul Rehman
Abdul Rehman

Reputation: 21

Pip is not working Within virtual environment (venv)

I install python and set its path too. When I check in CMD pip, It shows me the following...

C:\Users\maher>pip --version
pip 21.1.2""

But after activation of virtual environment when I want to install any packeg using pip, thew see following error.

(data) PS D:\Masters_FIT\4th\Webdatabese\Project\Code\Data_Collection> pip install tablib
Traceback (most recent call last):
  File "c:\users\maher\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\maher\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Masters_FIT\4th\Webdatabese\Project\Code\data\Scripts\pip.exe\__main__.py", line 4, in <module>      
ModuleNotFoundError: No module named 'pip'
(data) PS D:\Masters_FIT\4th\Webdatabese\Project\Code\Data_Collection>

My Project and environment director.

"data" is my environment name "Data_Collection" is the Project name.

any help or suggestion will be welcome and thanks in Advance.

Upvotes: 2

Views: 10693

Answers (3)

Joseph Samuel
Joseph Samuel

Reputation: 210

So I was having the same issue.
How I got that issue is

  1. I have created venv and home in pyvenv.cfg is pointing to my anaconda dir. I wanted to change it(change the version of python from 3.8.8 to 3.11.0).
  2. downloaded python 3.11.0 zip and pointed home in pyvenv.cfg to extract zip

Before editing home in pyvenv.cfg

Before editing home in pyvenv.cfg

After editing home in pyvenv.cfg

After edit pyvenv.cfg

Here the problem started

python --version is giving 3.11 but pip --version is throwing error

Error when I try command pip

This is the fix I tried

So, I have uncommented import site in pythonxx._pth (xx is python version downloaded)

before commenting:

before editing python311._pth located in python-3.11.0-embed-amd64 extracted zip

after removing the commit:

afterediting python311._pth located in python-3.11.0-embed-amd64 extracted zip

I also got this error when I python tried to use the cached wheel for installing packages

Error after editing python311._pth

then I tried to upgrade pip using cmd: c:\users\sam\desktop\py\django\tst\scripts\python.exe -m pip install --upgrade pip and then pip install pands worked

Note: when the python dir is changed (changing home var in pyvenv.cfg) uninstalling and re-installing packages will fix a few errors.

Upvotes: 0

Mahdi Zarrintareh
Mahdi Zarrintareh

Reputation: 176

Please run:

python -m ensurepip

and if not resolve the issue run this:

c:\users\maher\appdata\local\programs\python\python37-32\scripts\easy_install.exe pip

Upvotes: 6

Ali javanmardi
Ali javanmardi

Reputation: 69

May be by some reason pip and wheel did not install in your venv. You may try python -m pip install tablib to check if pip is working as a module.

Upvotes: 0

Related Questions