cannnot import module
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
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.
14.04 python3
 |Â
show 3 more comments
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.
14.04 python3
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
 |Â
show 3 more comments
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.
14.04 python3
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.
14.04 python3
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
 |Â
show 3 more comments
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
 |Â
show 3 more comments
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.
Projet folder appears in left side of Pycharm
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)
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
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
add a comment |Â
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.
Projet folder appears in left side of Pycharm
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)
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
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
add a comment |Â
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.
Projet folder appears in left side of Pycharm
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)
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
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
add a comment |Â
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.
Projet folder appears in left side of Pycharm
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)
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
Open project in PyCharm
You need to open the whole chapter9
folder in pycharm. In Pycharm do : File > Open and choose chapter9 folder.
Projet folder appears in left side of Pycharm
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)
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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