Import error with python console


 Hi ,

I have created a project and it contains several subdirectories and those directories are created within the PyCharm IDE. Inside one of those subdirectories I have a python file with the class defined. Now I can run the file with the IDE's run button. Now I want to test the code from the python console and while importing the module I am getting the moule import error
I check the following command to check which directory I am in from the console


import os



And I get the main path of project. Then use the cd command to get into the subdirectory where the python file is located, try to instantiate an object of a certain type , but I am getting the error:


import MyStuff

stuff = MyStuff()





Looks like a problem with 'cd'. Please change the working directory manually in Settings| Build, Execution, Deployment| Console| Python console. Does it help?


It is changed as suggested but the issue is not solved. 

Let me detail the process again for you. The main project directory is PyQt and inside it I have two nested subdirectories book/chap03. Inside PyQt/book/chap03, I have the python file defined and I can execute the file from the run button and it executes fine. Then I want to test from the Python console by instantiating different object of the type that I have just defined. I follow instruction to define the working directory from the Settings. When I try to import the module that I have created , I am getting the module import error even after the defined the working directory. Let me know if I have explained enough.




Hi! Please, try to check the option "Add source roots to PYTHONPATH"

  1. you have to edit on windows. The windows editor added something non-printing, perhaps a carriage-return (end-of-line in Windows is CR/LF; in Unix, it is LF only), or perhaps a CTRL-Z (windows end-of-file).You used WinSCP to copy the file to your Unix box. WinSCP thought: "This has something that's not basic text; I'll put a .bin extension to indicate binary data." The missing (now called means python doesn't understand toolkit as a package. you can try this to overcome the problem. You can follow python tutorials to learn python development and other issues related to python. 

Please sign in to leave a comment.