0

I can not import my module containing python class. Everywhere it's said that if both files are in the same directory import should work fine but it seems like it doesn't. I have the following structure of folders which ar ein the same folder:

chapter_9 folder contains files:
9-10.py
9-1.py
9-4.py
9-7.py
9-9.py
restaurant.py

when I type the following in the 9-10.py file

import restaurant

it's saying "No module named restaurant." Why it is so? Both files are in the same folder. Tell me please if you know where I should dig?

Thanks.

Azat
  • 83

1 Answers1

1

Open project in PyCharm

You need to open the whole chapter9 folder in pycharm. In Pycharm do : File > Open and choose chapter9 folder.

enter image description here

Projet folder appears in left side of Pycharm

enter image description here

To finish you can check python interpreter and root directory. Go in File > Settings > Project: Chapter9.

  • Project Interpreter must be valid.
  • Project Structure must have a valid content root (chapter9 folder)

enter image description here

PYTHONPATH

To ensure that Python search modules in your directory, you can set PYTHONPATH environnement variable by the following command :

export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/

Documentation to PYTHONPATH : https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH

yoann_dev
  • 151