8

I'm trying to execute a simple PY file and I'm getting the following error:

Traceback (most recent call last):
  File "docker_pull.py", line 8, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Looking at Python install folder I found requests module under: C:\Program Files (x86)\Python 3.7.1\Lib\site-packages\pip\_vendor\requests. How can I force Python to use the module already installed ?

P.S: I don't have internet connection in this machine.

2
  • 2
    Add C:\Program Files (x86)\Python 3.7.1\Lib\site-packages\pip\_vendor to your PYTHONPATH environment variable, or add it directly to sys.path in the code. Commented Sep 24, 2019 at 15:56
  • Thanks, it solve my problem. Commented Sep 24, 2019 at 15:59

2 Answers 2

9

This is a very typical issue, so I will leave this here for future reference.

If I have a project called: my_project

.
└── my_project
    ├── first_folder
    ├── second_folder
    └── third_folder

What you want to do is one of these two things:

  1. PYTHONPATH (only Python)

cd ~/my_project && export PYTHONPATH=$(pwd)

change dir to root dir, and export that dir to PYTHONPATH, so when Python runs it looks in the PYTHONPATH.

  1. PATH (everything)

cd ~/my_project && export PATH=$PATH:$(pwd)

Same as above!

This needed to live somewhere since it took me a while to figure out. So for anyone in the future who needs help with this!

Sign up to request clarification or add additional context in comments.

Comments

-1

Check the python version you are calling. Run "python --version". If it's not 3.7.1, that's the problem. If it returns a version beginning with "2", then try running the python3 binary instead.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.