Invoking my script works fine from within PyCharm
Project structure is as follows:
project_name
└── src
├─ bin
│ └─ file_to_run.py
└─ some_module
└─ __init__.py
I'm invoking the script from command line with
C:\path\to\venv\python.exe C:\foo\project_name\src\bin\file_to_run.py
and it gives me
ModuleNotFoundError: No module named 'some_module'
I've tried setting various values for %PYTHONPATH% including
cd project_name && set PYTHONPATH=.
set PYTHONPATH=C:\foo\project_name\src
set PYTHONPATH=C:\foo\project_name\src\bin
set PYTHONPATH=C:\foo\project_name\src\some_module
set PYTHONPATH="C:\foo\project_name\src\some_module; C:\foo\project_name\src\some_module"
and basically all of the combinations thereof, with quotes, without quotes, separated by colons and semicolons.
I've set a sources root in PyCharm, and when I run it in the IDE it has a script path, environment variables and working directory defined as well as the options 'add content roots' and 'add sources roots' 'to PYTHONPATH' checked.
I can't think of any more relevant information as to why it can't find that module.
Windows version 10, using the command prompt.
It looks like I wasn't activating my virtualenv before running so the python version was different as suggested by @furas.
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.