0

I'm facing a strange problem in Python imports. I've written a simple Python module, called test.py. It contains:

import wx

When I run this code in IDLE, it runs successfully. But when I run the same module through command-line, it gives me an ImportError: no module named wx. It is not an error related to wx library for two reasons. One, because it runs on IDLE. And two, I'm unable to run any module with an import statement in command-line.

PS: I've set all the environment variables. (C:\Python27\; C:\Python27\Scripts).

What may be the problem?

3
  • use print sys.path in your command-line to verify if your test path is included Commented Aug 12, 2015 at 6:35
  • 'when I type the following', the following? Commented Aug 12, 2015 at 6:47
  • If you type python what do you get? Type import sys and sys.path and see whether wx is in the path. Commented Aug 12, 2015 at 6:50

1 Answer 1

2

You should run the command line under your script folder.


For instance,

Your test.py was under the folder: ~/scripts/test.py,

then you should first change to this folder: cd ~/scripts

and run the python command-line: python or python test.py.


The reason is that:

You IDE has already changed to your file folder, since you can run it.

But the command-line was not.


Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure this addresses the problem as described. How would they get ImportError: no module named wx?

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.