7

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?

asked Jan 28, 2017 at 13:08
0

5 Answers 5

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.

  1. 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.

  1. Now import the sub-directory and the respective module that you want to use via the import command: import subdir.subdir.modulename as abc You should now be able to use the methods in that module.

enter image description here

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.

drapkin11
1,2152 gold badges14 silver badges24 bronze badges
answered Oct 21, 2017 at 10:52
Sign up to request clarification or add additional context in comments.

1 Comment

what if one of the path has a dot?
4

Set the environment variable PYTHONPATH=C:\Users\Rohil\Desktop\GetOldTweets-python-master\got (how exactly, depends on your operating system)

answered Jan 28, 2017 at 13:10

6 Comments

can you import the other module? also, make sure that your terminal sees the correct PYTHONPATH value
created a new variable in windows called 'PythonPath' and added C:\Users\Rohil\Desktop\GetOldTweets-python-master\got as the value. Still throws the same error
nope, cant import any module from that folder. How do i make sure that the terminal sees the correct pythonpath value on windows?
the variable should be IN CAPITAL letters. then, at command prompt, try echo %PYTHONPATH% and check that you see the correct value
Well, it worked so far, now you have a different problem than before, need more info. Also, make use that your init.py is empty file (does not import anything)
|
2
  • Does the models folder has an __init__.py file inside it ? Only then, it will be recognized as a module by python and import models would make sense.

So,

  • Create an empty __init__.py file in the models subfolder and then the code should work without any issues.

You should also look at this answer.

answered Jan 28, 2017 at 13:20

2 Comments

my models folder too has a _init_.py file. Still gives the error
my models folder has a _init_.py file which contains: from Tweet import Tweet
-2

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)

:)

answered Feb 12, 2020 at 14:48

1 Comment

Thanks. Adding sudo to python3 -m pip install "module_name" helped to me.
-3

if create d or using or custom python package

check our dir. correct.

** For python 3.7 user **

from. import module_name
answered Dec 31, 2019 at 6:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.