1

I just started learning Python.

In c:\Python27 I have created my first hello.py script.

It works when I type in the command line:

c:\Python27 python hello.py

Now I created another script, but in a different directory. This directory is in the PYTHONPATH.

mymodule.py:
  print("general")

  def fone():    
    print("special line")

When I extend the hello.py script:

import mymodule

print "Hello"
mymodule.fone()

The mymodule script/module gets found and is correctly imported, so the PYTHONPATH seems to be ok.

But when I type at the command line:

c:\Python python mymodule.py

I get the error:

python: can't open file 'mymodule.py': [Errno 2] No such file or directory

Why is this?

Thanks alot for help

2 Answers 2

2

You should specify the full path of the file unless it is in the current working directory.

python C:\path\to\mymodule.py

or you can use python -m ... if the module is in the directory (listed in PYTHONPATH):

python -m mymodule
Sign up to request clarification or add additional context in comments.

Comments

1

When you run python mymodule.py, it looks for mymodule.py in the current directory. You need to specify the full path.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.