cannnot import module

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












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.







share|improve this question




















  • Have you tried making an empty file called __init__.py? stackoverflow.com/questions/4142151/…
    – Katu
    Apr 19 at 10:13










  • I have tried to create empty init.py. No result. Also I tried to call like this: from .restaurant import Restaurant and then I get the error: No module named 'main.restaurant'; 'main' is not a package
    – Azat
    Apr 19 at 10:59







  • 1




    It' said in the link you have posted previously askubuntu.com/questions/470982/… that if it's module and it's in the same folder as the calling app or script I can simply write import restaurant and this should work but it doesn't. So seems confusing to me
    – Azat
    Apr 19 at 11:06











  • also making initi.py is required only if it's package but I have simple module. So no need for me doing that as I get this.
    – Azat
    Apr 19 at 11:13










  • @Azat In pycharm, did you open the chapter_9 folder or only the separated python files ?
    – yoann_dev
    Apr 20 at 9:10














up vote
0
down vote

favorite












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.







share|improve this question




















  • Have you tried making an empty file called __init__.py? stackoverflow.com/questions/4142151/…
    – Katu
    Apr 19 at 10:13










  • I have tried to create empty init.py. No result. Also I tried to call like this: from .restaurant import Restaurant and then I get the error: No module named 'main.restaurant'; 'main' is not a package
    – Azat
    Apr 19 at 10:59







  • 1




    It' said in the link you have posted previously askubuntu.com/questions/470982/… that if it's module and it's in the same folder as the calling app or script I can simply write import restaurant and this should work but it doesn't. So seems confusing to me
    – Azat
    Apr 19 at 11:06











  • also making initi.py is required only if it's package but I have simple module. So no need for me doing that as I get this.
    – Azat
    Apr 19 at 11:13










  • @Azat In pycharm, did you open the chapter_9 folder or only the separated python files ?
    – yoann_dev
    Apr 20 at 9:10












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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.







share|improve this question












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.









share|improve this question











share|improve this question




share|improve this question










asked Apr 19 at 8:14









Azat

3328




3328











  • Have you tried making an empty file called __init__.py? stackoverflow.com/questions/4142151/…
    – Katu
    Apr 19 at 10:13










  • I have tried to create empty init.py. No result. Also I tried to call like this: from .restaurant import Restaurant and then I get the error: No module named 'main.restaurant'; 'main' is not a package
    – Azat
    Apr 19 at 10:59







  • 1




    It' said in the link you have posted previously askubuntu.com/questions/470982/… that if it's module and it's in the same folder as the calling app or script I can simply write import restaurant and this should work but it doesn't. So seems confusing to me
    – Azat
    Apr 19 at 11:06











  • also making initi.py is required only if it's package but I have simple module. So no need for me doing that as I get this.
    – Azat
    Apr 19 at 11:13










  • @Azat In pycharm, did you open the chapter_9 folder or only the separated python files ?
    – yoann_dev
    Apr 20 at 9:10
















  • Have you tried making an empty file called __init__.py? stackoverflow.com/questions/4142151/…
    – Katu
    Apr 19 at 10:13










  • I have tried to create empty init.py. No result. Also I tried to call like this: from .restaurant import Restaurant and then I get the error: No module named 'main.restaurant'; 'main' is not a package
    – Azat
    Apr 19 at 10:59







  • 1




    It' said in the link you have posted previously askubuntu.com/questions/470982/… that if it's module and it's in the same folder as the calling app or script I can simply write import restaurant and this should work but it doesn't. So seems confusing to me
    – Azat
    Apr 19 at 11:06











  • also making initi.py is required only if it's package but I have simple module. So no need for me doing that as I get this.
    – Azat
    Apr 19 at 11:13










  • @Azat In pycharm, did you open the chapter_9 folder or only the separated python files ?
    – yoann_dev
    Apr 20 at 9:10















Have you tried making an empty file called __init__.py? stackoverflow.com/questions/4142151/…
– Katu
Apr 19 at 10:13




Have you tried making an empty file called __init__.py? stackoverflow.com/questions/4142151/…
– Katu
Apr 19 at 10:13












I have tried to create empty init.py. No result. Also I tried to call like this: from .restaurant import Restaurant and then I get the error: No module named 'main.restaurant'; 'main' is not a package
– Azat
Apr 19 at 10:59





I have tried to create empty init.py. No result. Also I tried to call like this: from .restaurant import Restaurant and then I get the error: No module named 'main.restaurant'; 'main' is not a package
– Azat
Apr 19 at 10:59





1




1




It' said in the link you have posted previously askubuntu.com/questions/470982/… that if it's module and it's in the same folder as the calling app or script I can simply write import restaurant and this should work but it doesn't. So seems confusing to me
– Azat
Apr 19 at 11:06





It' said in the link you have posted previously askubuntu.com/questions/470982/… that if it's module and it's in the same folder as the calling app or script I can simply write import restaurant and this should work but it doesn't. So seems confusing to me
– Azat
Apr 19 at 11:06













also making initi.py is required only if it's package but I have simple module. So no need for me doing that as I get this.
– Azat
Apr 19 at 11:13




also making initi.py is required only if it's package but I have simple module. So no need for me doing that as I get this.
– Azat
Apr 19 at 11:13












@Azat In pycharm, did you open the chapter_9 folder or only the separated python files ?
– yoann_dev
Apr 20 at 9:10




@Azat In pycharm, did you open the chapter_9 folder or only the separated python files ?
– yoann_dev
Apr 20 at 9:10










1 Answer
1






active

oldest

votes

















up vote
1
down vote













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






share|improve this answer






















  • when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
    – Azat
    Apr 19 at 11:15











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1026322%2fcannnot-import-module%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













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






share|improve this answer






















  • when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
    – Azat
    Apr 19 at 11:15















up vote
1
down vote













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






share|improve this answer






















  • when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
    – Azat
    Apr 19 at 11:15













up vote
1
down vote










up vote
1
down vote









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






share|improve this answer














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







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 23 at 12:52

























answered Apr 19 at 9:38









yoann_dev

767




767











  • when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
    – Azat
    Apr 19 at 11:15

















  • when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
    – Azat
    Apr 19 at 11:15
















when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
– Azat
Apr 19 at 11:15





when I type export PYTHONPATH=$PYTHONPATH:/path_to/chapter_9 folder/ pycharm is underlining it with red saying that it's unresolved reference.
– Azat
Apr 19 at 11:15


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1026322%2fcannnot-import-module%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491