ImportError: No module named psycopg2.extensions - python

I am trying to create an app using GeoDjango and I am completely new to this. After some (failing) attempts at making SpatiaLite work, I decided to try out PostgreSQL. I am following the GeoDjango tutorial, and I am stuck at the python manage.py sqlall world line. When I ran that command (or python manage.py syncdb), I got ImportError: No module named psycopg2.extensions. I looked online and realized I needed to install psycopg2, which I did via MacPorts with sudo port install py27-psycopg2. I reran the program and got the same error. I restarted my computer and ran the program again, and still got the same error. Does anyone know anything else that might have caused this?
Thanks!
PS. If anyone cared to know, I was stuck at the same command while testing out SpatiaLite. I consistently received the 'DatabaseOperations' object has no attribute 'geo_db_type'error. I looked around the internet, didn't find any answer and decided to move on for the time being and maybe try again later.
PSS. I am working on Mac OS X 10.7.5

Related

Why am I seeing "No module named '_tkinter" when I deploy django to heroku?

django works well on my local machine. But, when I deploy it to heroku, I see "ModuleNotFoundError" "No module named '_tkinter'". Though, I never imported "_tkinter" or "tkinter" in my code. Your help will be appreciated. Thank you.
ModuleNotFoundError at /
No module named '_tkinter'
Request Method: GET
Request URL: https://howididit.herokuapp.com/
Django Version: 4.0.6
Exception Type: ModuleNotFoundError
Exception Value:
No module named '_tkinter'
Exception Location: /app/.heroku/python/lib/python3.10/tkinter/init.py, line 37, in
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.10.5
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python310.zip',
'/app/.heroku/python/lib/python3.10',
'/app/.heroku/python/lib/python3.10/lib-dynload',
'/app/.heroku/python/lib/python3.10/site-packages']
If you don't use Tkinter, just remove it from /forms.py. otherwise it'll be imported.
If you want to use tkinter,then consider the below process
please try adding tkinter to your requirements.txt. If it fails, even after that, check if you have added Python buildpack. If both the cases pass, try shelling into your Heroku instances and run the following command:
sudo apt install python3-tk
This will install Tkinter library in your instance of Heroku. That will resolve your error.
I found out these from pyexpat import model from turtle import title from attr import fields where imported in my forms.py. After deleting them, The problem was solved. Again, thank you all guys for your time, I really appreciate it.
Okay so for anyone looking at this in the future and banging their head against the desk...this is what worked for me:
I started with a new Hello World app and started adding bits of my original code until i got to the error
found out that one of the modules I was using : icu, was using tkinter and i needed to install the Pyicu module instead
pip installed directly into heroku bash console instead of through my app
None of the answers i found online had worked for me, and I think its because this error isnt from having tkinter directly in your app, but from another module thats calling it.
When in doubt do what I did and start a new project from scratch and add chunks of code until you get the error to see which module is creating it
Dont forget to change DEBUG to False in your settings file

ModuleNotFoundError: No module named 'mysql' with mysql-connector-python already installed

I'm trying to connect my python scripts to an MySQL or MariaDB Server on my RaspberryPi4.
My python script right now just contains import mysql.connector. But when I try to start it via sudo python3 startdb.py I just get import mysql.connector ModuleNotFoundError: No module named 'mysql' as an error.
I get an other error, when I start the script via sudo python startdb.py: import mysql.connector ImportError: No module named mysql.connector.
I searched for a solution on many sites or forums. I mostly just found various versions of pip install mysql-connector-python (also with pip3, mysql-connector-python-rf or mysql-connector) to run but none of them worked for me. The only difference I recognized is that I previously got the error ModuleNotFoundError with both sudo python and sudo python3, but now I only get it with sudo python3.
Does anyone know how to solve this?
Could the fact that my script isn't in a sub-directory of /home/pi/, but instead of /home/, be the problem?
Edit: I just tried executing the script via the desktop mode using my mouse and just clicking on run and it worked. But when I'm using the command line in desktop mode or with a SSH session it doesn't work.
Another Edit: It looks like when I'm starting the script without sudo it'll work just fine. Don't actually know why's that, but I'm good for now. But would be very interesting to know and understand why the sudo makes it "crash".
Thanks and happy to hear some solutions :D
Cooki
raspbian give user mode in running, just in Desktop gives some permission to user for run app as root to access all necessary attributes , use sudo with all initial steps when you download and install project package's

SQLAlchemy stops working with MySQLdb out of nowhere

For the past couple days, it's been working fine. But today, I was trying fix some encoding issue, and it just suddenly stopped working. I reverted my code back to what it was like from before, but for some reason the error is still there. (And so is the encoding issue, sadly.)
I am using MySQL with MySQLdb on Python 3.6.2 and Anaconda. I am aware of MySQLdb's incompatibility with Python 3 and with Anaconda. However, I do not want to use Python 2 or a different driver.
I have worked around this by installing mysqlclient, and I am able to do import MySQLdb in the Qt console. I was also able to create an engine with below code literally 30 minutes ago.
from sqlalchemy import create_engine
engine = create_engine('mysql://user:pass#localhost:3306/db?charset=utf8')
I checked my code with the one I had on the remote repo just to make sure there was no mistake. It's exactly the same. Yet now I'm getting the following error:
NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql
Which seems very odd considering that I have both. This error is seen when I run my script in the Qt console with %run myscript.py. I've been doing that since yesterday without any issues.
I am not using any virtual environments as I found it a pain to manage them on Windows and with Anaconda. I also checked that MySQLdb is importable in the console before running the script. So I know the module is properly installed.
I tried to figure out what's going on, and during my investigation I found out that I'm missing sqlalchemy.connectors module, but I'm not sure if that actually is an issue because I can't find any similar issues online. Here's what I did to get that error:
from sqlalchemy.dialects import mysql
ModuleNotFoundError: No module named 'sqlalchemy.connectors'
Does anyone know what the issue is? This is really frustrating because this seems to be completely out of blue :/
** I just tested whether other drivers work (i.e. pymysql), and it doesn't. I think it's because sqlalchemy is rejecting the dialect regardless of the driver.
EDIT: To reproduce (at least on my machine at the moment) I only need 2 lines.
from sqlalchemy import create_engine
engine = create_engine('mysql://user:pass#localhost:3306/db')
EDIT2: I identified it as an Anaconda issue, however I'm still unsure what the cause is.
Clean reinstall of sqlalchemy have fixed the issue.
Can't believe that wasn't the first thing I tried.
I still have no idea how it got corrupted, though.
$ conda uninstall sqlalchemy
$ conda install sqlalchemy

ImportError - Not finding Python Packages

I am stuck trying to get an application via Apache web server. I keep getting the following error.
ImportError: No module named flask
I believe this is because it might be pointing to the wrong Python. I had anaconda, but have removed that. When I check to see all the versions of Python, the following show up.
which -a python
/usr/local/bin/python
/usr/bin/python
Error: No module named flask
When I print the environment variables, here is the following:
printenv
PYTHONPATH=/usr/local/lib/python2.7/site-packages
The packages are all there as I have verified that with a pip freeze. Any help would be greatly appreciated as I have been stuck on this for a while. Thanks!
Your problem is quiet unclear answering from what i understood.
It seems like you have 2 python installed on your device. First find for which python all the modules are installed . Then simply mention the path of that python on the top of your script. If your case
#!/usr/bin/env python
or
#!/usr/local/env python

Python OpenCV: ImportError Module Not Found

I had installed OpenCV, and it was working just fine. But I noticed that a few libraries were missing.
So I decided to install another copy. I moved the working copy to another directory, and started the install of the new one. I was having trouble with this new install, so I cancelled it and moved my old OpenCV install back to its original directory.
But now, my old install doesn't work anymore. Each time I try to run something, it says "ImportError: No module named cv2" or "ImportError: No module named cv" (depending on what was being imported in the file).
What do I do to fix this? I remember encountering a similar issue the first time I installed and ran this copy of OpenCV, and something had to be changed with the Python Path to work correctly. I can't quite remember, and I'm kind of confused about why those settings would change, if they indeed have.
Please let me know what I can do to rectify this. I am using OS X 10.9. Thank you.
UPDATE: I added this to my .bash_profile: export PYTHONPATH=/Users/santosh/opencv-2.4.7/build/lib:$PYTHONPATH. But now when I run opencv samples, I get "Segmentation fault: 11". Any thoughts?

Categories

Resources