0

I have a directory structure like this:

my_project
   .idea
   src
       config.ini
       method.py
       ... other py modules

When I open the project in PyCharm and run with the configuration below, it runs perfectly. It runs src.method as a module using an Anaconda 3 environment. The src.method module uses relative imports from other modules in src and takes config.ini as an argument.

I am trying to run the module in the same way through the Windows command line from src as the working directory

C:\Users\deimos\Anaconda3\envs\cveureka\python.exe -m src.method "config.ini"

but this gives a ModuleNotFoundErrorsaying it could not find src. I tried replacing src.method with just method but that gives ImportError: attempted relative import with no known parent package.

I have also tried setting the PYTHONPATH before running the module with

setlocal
set PYTHONPATH=%2

like in this answer, but to no effect.

It there a way to set up the command line to replicate the way that PyCharm runs the module?

enter image description here

rovyko
  • 4,068
  • 5
  • 32
  • 44
  • C:\Users\deimos\Anaconda3\envs\cveureka\python.exe -m C:/PATHTOPROJECT/my_project/src/method.py "config.ini" – MachineLearner Mar 06 '20 at 07:12
  • @MachineLearner unfortunately this gives `Error while finding module specification for 'D:\\userdata\\deimos\\Dropbox\\work\\research\\seaice\\c20\\src\\method.py' (ModuleNotFoundError: No module named 'D:\\userdata\\deimos\\Dropbox\\work\\research\\seaice\\c20\\src\\method')` – rovyko Mar 06 '20 at 07:22
  • As far as I can see you are storing your project on another drive. This means that you need to first change your drive. The easiest way would be to take your project and move it to the same drive (not necessarily same folder) as your python.exe. – MachineLearner Mar 06 '20 at 09:47
  • I tried that but unfortunately it didn't do anything – rovyko Mar 06 '20 at 17:16

0 Answers0