Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'twitter' #6

Open
tomtom1337 opened this issue Mar 31, 2023 · 7 comments
Open

ModuleNotFoundError: No module named 'twitter' #6

tomtom1337 opened this issue Mar 31, 2023 · 7 comments

Comments

@tomtom1337
Copy link

Hi and thanks for the great work!

I've got an issue with loading the local twitter module from the modules folder:

Traceback (most recent call last):
  File "poastal.py", line 7, in <module>
    from twitter import twitter_email
ModuleNotFoundError: No module named 'twitter'

Workaround for me was to add the modules folder to the import command in the poastal.py

#import modules
from modules.twitter import twitter_email

And now it's working :)

@chanoir2303
Copy link

Recommendation is to install your dependencies into a virtual environment

@tomtom1337
Copy link
Author

Recommendation is to install your dependencies into a virtual environment

This does not solve my issue... still No module named 'twitter'.
The only solution is to add modules. to load the local modules correctly

@chanoir2303
Copy link

Can you reproduce how did you install the project requirements for us?

@jakecreps
Copy link
Owner

Did you change any folder names?

sys.path.append(os.path.abspath('./modules'))

This should import the location of all of the modules into the script.

@tomtom1337
Copy link
Author

I've tried it on a fresh installation of Linux Mint 21.1 in Virtual Box:

v@v-VirtualBox:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Linuxmint
Description:	Linux Mint 21.1
Release:	21.1
Codename:	vera
v@v-VirtualBox:~$ python3 --version
Python 3.10.6

Installation:

@v-VirtualBox:~$ git clone https://github.com/jakecreps/poastal
Klone nach 'poastal' …
remote: Enumerating objects: 178, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (76/76), done.
remote: Total 178 (delta 29), reused 0 (delta 0), pack-reused 101
Empfange Objekte: 100% (178/178), 150.11 KiB | 3.00 MiB/s, fertig.
Löse Unterschiede auf: 100% (65/65), fertig.
v@v-VirtualBox:~$ cd poastal/
v@v-VirtualBox:~/poastal$ pip install -r requirements.txt
[ ... ]
Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.2 Werkzeug-2.2.3 flask-2.2.3 flask_cors-3.0.10 itsdangerous-2.1.2
v@v-VirtualBox:~/poastal$ python3 backend/poastal.py 
Traceback (most recent call last):
  File "/home/v/poastal/backend/poastal.py", line 7, in <module>
    from twitter import twitter_email
ModuleNotFoundError: No module named 'twitter'

I've added print(sys.path) to check if the sys.path.append is working:

['/home/v/poastal/backend', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/v/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.10/dist-packages', '/home/v/poastal/modules']

Only solution is to load all the local modules with
from modules.xxx import xxx

@turnkit
Copy link

turnkit commented Apr 28, 2023

weird. Was trying to troubleshoot why I never get a prompt to enter an email and I did notice this...

If I run the poastal.py from the poastal directory like this then I get this module error. But if I cd into backend and then run it it seems to start fine (but I can never find a place to enter the email as the web page just shows "no email provided."

$ python ./backend/poastal.py
Traceback (most recent call last):
File "/home/user/poastal/./backend/poastal.py", line 7, in
from twitter import twitter_email
ModuleNotFoundError: No module named 'twitter'

vs

$ python ./poastal.py

  • Serving Flask app 'poastal'
  • Debug mode: on
    WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on http://127.0.0.1:8080
    Press CTRL+C to quit
  • Restarting with watchdog (inotify)
  • Debugger is active!
  • Debugger PIN: 214-718-896
    127.0.0.1 - - [28/Apr/2023 10:10:48] "GET / HTTP/1.1" 200 -
    127.0.0.1 - - [28/Apr/2023 10:11:40] "GET /index.html HTTP/1.1" 404 -

@tomtom1337
Copy link
Author

So the problem is that if you don't run poastal.py from the backend folder itself it throws the ModuleNotFoundError because it looks for .../poastal/modules instead of .../poastal/backend/modules

So you may close this issue or you can add my workaround modules.xxxx to run poastal.py from anywhere 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants