0

I clone a python project from github and a virtual environment has been set up in the project.

Then I set up this virtual environment in the python interpretor and module "urllib3" is shown in the package list.

However when I run the project, the error occurs

No module named 'urllib3'

It seems that the virtual environment does not take effects but I am really confused why.

Plus, I run this program in terminal by

pytest xxx.py

I am not sure whether this is a reason for the problem. If it is, how to fix it?

Qianyu
  • 9
  • 2
  • if you see a 'venv' folder in your repo, I suggest deleting it and recreating your own. This is because the folder includes a link to the local disk python executable, which will not be found on your disk. – Huy Sep 18 '21 at 07:13
  • well I tried the original project and it works all fine when I uses run in Pycharm instead of command in terminal. I am not sure whether this problem is caused because I run the program in the terminal. – Qianyu Sep 18 '21 at 07:23
  • nope, your running program in the terminal won't affect its virtualenv. do you mind posting the link to the repo? – Huy Sep 18 '21 at 07:27
  • sorry but this is a private project... – Qianyu Sep 18 '21 at 07:57
  • it's ok, I've added an answer. Hope that helps : ) – Huy Sep 18 '21 at 08:37

1 Answers1

0

The most practical solution I can propose to this problem is to recreate a virtual environment of your own. Since you mentioned you could run the program in Terminal, first activate the cloned environment.

On Linux or Mac:

source venv/bin/activate

On Windows:

source venv/Scripts/activate

Then once it's activated, get the list of packages:

pip freeze > requirements.txt
deactivate

Remove cloned environment:

rm -rf venv

Recreate a new one:

python -m venv venv
source venv\bin\activate (Or Scripts if on Windows)
pip install -r requirements.txt
Huy
  • 794
  • 6
  • 10