0

I'm trying to run a python script on my Windows 10 Computer. The structure of the directory looks as follows

MyProject
   - src
      - main.py
      __init__.py

      - features
          - featureExtraction.py
          - __init__.py

The main folder is "MyProject". In "MyProject" is a subfolder called "src". In "src" the files "main.py" and "init.py" as well as the folder "features" exists. In the folder "features" there are the files "featureExtraction.py" and "init.py".

In "main.py" I have the following import:

import src.features.featureExtraction

When I run main.py within pycharm everything works, but when I start the script on the command line using "python main.py" (beeing in the src folder), then I'm getting an error:

ModuleNotFoundError: No module named 'src'".

Why does this happen?

1
  • 1
    Try: import features.featureExtraction Commented Nov 24, 2017 at 16:33

1 Answer 1

1

You said you executed import src.features.featureExtraction while in the src folder. That import makes sense only while you are in the parent MyProject folder.

In pycharm prefs, search for Project Structure and notice the content root (MyProject) that it is using. That explains the different behavior you saw from IDE and from command line.

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

2 Comments

Ok so I have to use import features.featureExtraction. But how can I make it run both in the IDE and command line? I think the IDE needs then import src.features.featureExtraction
In pycharm prefs, search for Project Structure, and right click to add source folders as appropriate. This is similar to changing sys.path or PYTHONPATH.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.