Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
command prompt
#1
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
Reply
#2
please Show the code, including top most __init__.py file
Reply
#3
(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?
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
(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
Reply
#6
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?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
(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
Reply
#8
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?
Reply
#9
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the difference between Command Prompt and Sublimes yaoyao22 1 594 Jul-09-2023, 02:56 PM
Last Post: snippsat
  Facing Problem while opening a file through command prompt vlearner 4 1,857 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,232 Dec-20-2020, 04:23 AM
Last Post: adifrank
  Running Python in Command Prompt Anwar 3 3,003 Nov-15-2020, 03:15 PM
Last Post: snippsat
  starting python from windows command prompt MaartenRo 4 2,748 Sep-04-2020, 12:25 PM
Last Post: MaartenRo
  Will not print in command prompt PandaCode 12 12,831 May-06-2020, 03:48 AM
Last Post: PandaCode
  Script works when executed from command prompt but not when executed in SDP Tippex 0 1,965 Apr-07-2020, 04:26 PM
Last Post: Tippex
  Can read files in command prompt but not IDE Exsul 2 2,121 Sep-13-2019, 01:40 AM
Last Post: jsira2003
  Command Prompt Issue benzenegirl 2 2,523 Oct-25-2018, 03:09 PM
Last Post: The_Raven
  Pyinstaller to execute a script in command prompt Ciroxxx 0 2,067 Sep-18-2018, 10:17 AM
Last Post: Ciroxxx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020