Python Forum
command prompt - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: command prompt (/thread-14386.html)



command prompt - saisankalpj - Nov-27-2018

i have a code which runs through pycharm.To run through command prompt i have set the environment variables like PYTHON_HOME which gives python 36 location and path variables.But while running through command prompt the first line of file which has import statements like "from one import *" is raising error like no module named a .This is structure for example i followed
parent/
    __init__.py
    one/
        __init__.py
    two/
        __init__.py
    three/
        __init__.py



RE: command prompt - Larz60+ - Nov-27-2018

please Show the code, including top most __init__.py file


RE: command prompt - saisankalpj - Nov-27-2018

(Nov-27-2018, 12:48 PM)Larz60+ Wrote: please Show the code, including top most __init__.py file
code i cant show
but that structure was sample only.
but while running the code through command prompt i am getting error from import statements like if i have "from a import *",the error is like no module named a.
the init.py files are empty for me.should i include the import statements in __init__.py file to make it work through command prompt?


RE: command prompt - ichabod801 - Nov-27-2018

Your structure doesn't include a module named 'a'. If you want the import to work, you either need the module in the current working directory or in your PYTHONPATH.


RE: command prompt - saisankalpj - Nov-27-2018

(Nov-27-2018, 02:00 PM)ichabod801 Wrote: Your structure doesn't include a module named 'a'. If you want the import to work, you either need the module in the current working directory or in your PYTHONPATH.

Ok this is my exact structure
parent/
    
    one/
        __init__.py
        a.py
    two/
        __init__.py
        b.py
    
In b.py file i have a import like from one.a import *(in pychsrm)
When i run the command after going to <c:/users/parent > like python two/b.py i get error like
No module named one. Please tell me what steps i need to follow so code works through command prompt


RE: command prompt - ichabod801 - Nov-27-2018

This is all very confusing. You've given us three different imports with three different file structures. It's working on my machine. We need more clarity and more information. What is your sys.path?


RE: command prompt - saisankalpj - Nov-27-2018

(Nov-27-2018, 07:28 PM)ichabod801 Wrote: This is all very confusing. You've given us three different imports with three different file structures. It's working on my machine. We need more clarity and more information. What is your sys.path?

Yes it works in IDE not cmd.the last structure which i have given is the correct structure.i dont know why import error comes


RE: command prompt - nilamo - Nov-27-2018

Does parent have an __init__.py?
Do any of the folders have a __main__.py?
Which file are you running?
Is your current working directory the same as whichever file you're running? ie, are you running /> python parent/one/a.py, /parent/> python one/a.py, /parent/one/> python a.py, or something different?

What's the result of python --version?
Is that the same version that pycharm is configured to use?


RE: command prompt - saisankalpj - Nov-28-2018

(Nov-27-2018, 08:38 PM)nilamo Wrote: Does parent have an __init__.py?
Do any of the folders have a __main__.py?
Which file are you running?
Is your current working directory the same as whichever file you're running? ie, are you running /> python parent/one/a.py, /parent/> python one/a.py, /parent/one/> python a.py, or something different?

What's the result of python --version?
Is that the same version that pycharm is configured to use?

None of folders have __main__.py file .what should i keep in main file.
Should inkeep the imports which are not getting recognized? I am running the file like icode]/parent/> python one/a.py[/icode], Yes the version is same in both

(Nov-28-2018, 04:13 AM)saisankalpj Wrote:
(Nov-27-2018, 08:38 PM)nilamo Wrote: Does parent have an __init__.py?
Do any of the folders have a __main__.py?
Which file are you running?
Is your current working directory the same as whichever file you're running? ie, are you running /> python parent/one/a.py, /parent/> python one/a.py, /parent/one/> python a.py, or something different?

What's the result of python --version?
Is that the same version that pycharm is configured to use?

None of folders have __main__.py file .what should i keep in main file.
Should inkeep the imports which are not getting recognized? I am running the file like /parent/> python one/a.py, Yes the version is same in both.parent doesnt have __init__.py file