I am getting this error
Traceback (most recent call last):
File "Exporter.py", line 3, in <module>
import sys,getopt,got,datetime,codecs
File "C:\Users\Rohil\Desktop\GetOldTweets-python-master\got\__init__.py", line 1, in <module>
import models
ModuleNotFoundError: No module named 'models'
my directory tree is:
C:\Users\Rohil\Desktop\GetOldTweets-python-master\got
this contains 2 folders: manager and models and 1 __init__.py file with the code :
import models
import manager
i am executing a file with the path: C:\Users\Rohil\Desktop\GetOldTweets-python-master\Exporter.py
I can't figure out what the issue is. can anyone assist me?
5 Answers 5
If you have created a directory and sub-directory then follow the below steps and please keep in mind that a directory must have an __init__.py file for python to recognize it as a package.
- First run this to see all paths being searched by python:
import sys
sys.path
You must be able to see your current working directory in that list.
- Now import the sub-directory and the respective module that you want to use via the
importcommand:import subdir.subdir.modulename as abcYou should now be able to use the methods in that module.
As you can see in this screenshot above I have one parent directory and two sub-directories. Under the second sub-directory I have a module named CommonFunction. On the console to the right you can see my working directory after execution of sys.path.
1 Comment
Set the environment variable PYTHONPATH=C:\Users\Rohil\Desktop\GetOldTweets-python-master\got (how exactly, depends on your operating system)
6 Comments
C:\Users\Rohil\Desktop\GetOldTweets-python-master\got as the value. Still throws the same errorecho %PYTHONPATH% and check that you see the correct value- Does the
modelsfolder has an__init__.pyfile inside it ? Only then, it will be recognized as a module by python andimport modelswould make sense.
So,
- Create an empty
__init__.pyfile in themodelssubfolder and then the code should work without any issues.
You should also look at this answer.
If you are using python3 but are installing the API through 'pip install 'such and such'. It's not gonna work on python3 console. Therefore, you'd better use 'sudo python3 -m pip install 'such and such''. Then it's gonna work! (at least for ubuntu stuff)
:)
1 Comment
sudo to python3 -m pip install "module_name" helped to me.if create d or using or custom python package
check our dir. correct.
** For python 3.7 user **
from. import module_name