update Error Installation ErrorI am trying to access a database using python.when i am executing my script its giving error, Import Error:-No module named MySQL . I have even tried it to run with lower versions of python but the same error came.I tried to install the MySQL package using the command sudo apt-get install python-mysqldb but it throwing some error.
So i write a answer, so that the question could be marked as "answered".
The problem was losing internet connection. APT need internet connection to download the packages from source.
For someone, who want to install python module MySQLDB in Debian or Ubuntu:
apt-get update
apt-get install python-mysqldb
If you want to install MySQLDB from pip, you need to install all the prerequisites for python-mysqldb first (for virtualenv)
apt-get build-dep python-mysqldb
pip install mysql-python
Related
I am trying to run a piece of code using paramiko, but I get the error message ImportError: No module named cryptography.hazmat.backends. Both paramiko and cryptography are already installed.
As far as I can read on various forums, I need to install libffi-dev (and maybe also libssl-dev). However, all solutions I can find are either for Ubuntu or Mac OS. How do I install them on Windows 10?
Solved the issue by running
pip install cryptography --force-reinstall
and
pip install paramiko --force-reinstall
I'm playing with my first Raspberry Pi 3 project, and I've hit a snag. I've found some example code which uses MySQL import MySQLdb as mdb, but when I try to run the code I get a 'No module named 'MySQLdb''...
I've been googling for ages now, and I'm getting no where. Here's a few of the options I've tried:
pip install mysql-python
sudo pip install mysql-python
sudo apt-get install python-mysqldb
sudo apt-get install libmysqlclient-dev
Any suggestions?
From this post, try:
apt-get install python-dev libmysqlclient-dev
pip install MySQL-python
I am having trouble installing a Django app (Mezzanine) on Ubuntu 14.04. I've installed most necessities using apt-get (except for django-compressor and south -used pip), including psycopg2 for Postgres. However when I go to run python manage.py createdb it gives this error:
Error loading psycopg2 module: No module named psycopg2
This is the command I'm using to install psycopg2:
sudo apt-get install python-psycopg2
What am I doing wrong? Should I use pip to install psycopg2. I went to the website and it recommends installing through your OS package manager instead of pip.
I am working in a virtualenv except for when I am installing the psycopg2 elements....
If you need psycopg2 for a system installed program, then install it with the system package manager. If you need it for a program in a virtualenv, install it in that virtualenv.
. env/bin/activate
pip install psycopg2
Note that on many distros, the development headers needed for compiling against libraries are not installed by default. For psycopg2 on Ubuntu you'll need the python and postgresql headers.
sudo apt-get install python-dev libpq-dev
psycopg 2.7 now issues a warning that it will stop providing binary releases due to compatibility issues.
The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
See the release announcement for a thorough explanation. To handle the warning, tell pip not to download the pre-built wheel for psycopg2.
pip install --no-binary psycopg2 psycopg2
For me, to resolve this issue on Ubuntu 14.04 with virtualenv I had to
sudo apt-get install python3.5-dev
then I could run
pip install psycopg2
The psycopg you installed through apt-get is not visible from inside the virtual env.
You should install it through pip
pip install psycopg2
after sourcing your environment.
I am referring the following tutorial to make a login page for my web application.
http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982
I am having issue with the database.
I am getting an
ImportError: No module named MySQLdb
when I execute
http://127.0.0.1:5000/testdb
I have tried all possible ways to install python mysql, the one mentioned in the tutorial, easy_install, sudo apt-get install.
I have installed mysql in my virtual env. My directory structure is just the same as whats explained in the tutorial. The module is sucessfully installed in my system and still I am getting this error.
Please help. What could be causing this.
If you're having issues compiling the binary extension, or on a platform where you cant, you can try using the pure python PyMySQL bindings.
Simply pip install pymysql and switch your SQLAlchemy URI to start like this:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://.....'
There are some other drivers you could also try.
Or try this:
apt-get install python-mysqldb
may you try
pip install mysqlclient
My issue is :
return __import__('MySQLdb')
ImportError: No module named MySQLdb
and my resolution :
pip install MySQL-python
yum install mysql-devel.x86_64
at the very beginning, i just installed MySQL-python, but the issue still existed. So i think if this issue happened, you should also take mysql-devel into consideration.
Hope this helps.
I got this issue when I was working on SQLAlchemy. The default dialect used by SQLAlchemy for MySQL is mysql+mysqldb.
engine = create_engine('mysql+mysqldb://scott:tiger#localhost/foo')
I got the "No module named MySQLdb" error when the above command was executed. To fix it I installed the mysql-python module and the issue was fixed.
sudo pip install mysql-python
It depends on Python Version as well in my experience.
If you are using Python 3, #DazWorrall answer worked fine for me.
However, if you are using Python 2, you should
sudo pip install mysql-python
which would install 'MySQLdb' module without having to change the SQLAlchemy URI.
So I spent about 5 hours trying to figure out how to deal with this issue when trying to run
./manage.py makemigrations
With Ubuntu Server LTS 16.1, a full LAMP stack, Apache2 MySql 5.7 PHP 7 Python 3 and Django 1.10.2 I really struggled to find a good answer to this. In fact, I am still not satisfied, but the ONLY solution that worked for me is this...
sudo apt-get install build-essential python-dev libapache2-mod-wsgi-py3 libmysqlclient-dev
followed by (from inside the virtual environment)
pip install mysqlclient
I really dislike having to use dev installs when I am trying to set up a new web server, but unfortunately this configuration was the only mostly comfortable path I could take.
In ubuntu 20 , you can try this :
sudo apt-get install libmysqlclient-dev
sudo apt-get install gcc
pip install mysqlclient
While #Edward van Kuik's answer is correct, it doesn't take into account an issue with virtualenv v1.7 and above.
In particular installing python-mysqldb via apt on Ubuntu put it under /usr/lib/pythonX.Y/dist-packages, but this path isn't included by default in the virtualenv's sys.path.
So to resolve this, you should create your virtualenv with system packages by running something like:
virtualenv --system-site-packages .venv
yum install MySQL-python.x86_64
worked for me.
for Ubuntu 20.04 with python3
sudo apt-get install python3-mysqldb
by default, this work for me
Create a sqlite engine instance
engine = create_engine('mysql://username:password#your_host/your_dbname')
OR
pip install pymysql
Create a sqlite engine instance
create_engine('mysql://...
I have the same issue the install mySQL connector and resolved
pip install mysqlclient
more details ->
SQLAlchemy official docs
Got so many errors related to permissions and what not. You may wanna try this :
xcode-select --install
sudo apt-get install python-mysqldb
Here's what I did:
First, install a python package:
pip3 install PyMySQL
Then add the following lines of code to your Project:
import pymysql
pymysql.install_as_MySQLdb()
this should fix your issue by now, the following one is optional and for anyone who is using SqlAlchemy to connect to mysql server:
Replace engine = create_engine("mysql://YOURMYSQLURL")
to:
engine = create_engine("mysql+pymysql://YOURMYSQLURL")
I have faced this type of error when I tray to build python flask eccomerce web-application
ModuleNotFoundError: No module named 'MySQLdb'?
I tray to see the version of python installed on my window 10
it was python 3.10
so MYSQL-PYTHON is compatable with the other version of python 3.8
I delet python 3.10 and I nstalled the version python 3.8
It become ok!
python --version
3.8
pip --version
python 3.8
so install the connector
pip install MYSQL-PYTHON
successfuly installed
I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python manage.py runserver' in Terminal to get my localhost up but when I run the command, I see this response...
Error: No module named psycopg2.extensions
I'm not sure what this means - I have tried to download psycopg2 but can't seem to find a way to download psycopg2 using homebrew. I have tried easy_install, pip install and sudo but all return errors like this...
Downloading http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz
Processing psycopg2-2.4.5.tar.gz
Writing /tmp/easy_install-l7Qi62/psycopg2-2.4.5/setup.cfg
Running psycopg2-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l7Qi62/psycopg2-2.4.5/egg-dist-tmp-PBP5Ds
no previously-included directories found matching 'doc/src/_build'
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
How to fix this?
The first thing to do is to install the dependencies.
sudo apt-get build-dep python-psycopg2
sudo apt install python3-psycopg2 # Python 3
After that go inside your virtualenv and use:
pip install psycopg2-binary
These two commands should solve the problem.
pip install psycopg2-binary
The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
For Django 2 and python 3 install psycopg2 using pip3 :
pip3 install psycopg2
I installed it successfully using these commands:
sudo apt-get install libpq-dev python-dev
pip install psycopg2
For macOS Mojave just run pip install psycopg2-binary. Works fine for me, python version -> Python 3.7.2
first install apt-get install python-setuptools
then try easy_install psycopg2
This is what helped me on Ubuntu if your python installed from Ubuntu installer. I did this after unsuccessfully trying 'apt-get install' and 'pip install':
In terminal:
sudo synaptic
then in synaptic searchfield write
psycopg2
choose
python-psycopg2
mark it for installation using mouse right-click and push 'apply'. Of course, if you don't have installed synaptic, then first do:
sudo apt-get install synaptic
I ran into this same issues recently and this code worked.
sudo apt-get install libpq-dev python-dev-is-python3
Then
pip3 install psycopg2
In python 3.4, while in a virtual environment, make sure you have the build dependencies first:
sudo apt-get build-dep python3-psycopg2
Then install it:
pip install psycopg2
On Alpine Linux (majority of the docker containers) do:
apk add postgresql-dev
Then:
pip install psycopg2-binary
pip3 install django-psycopg2-extension
I know i am late and there's lot of answers up here which also solves the problem. But today i also faced this problem and none of this helps me. Then i found the above magical command which solves my problem :-P . so i am posting this as it might be case for you too.
Happy coding.
I used the extension after only importing psycopg2:
import psycopg2
...
psycopg2.extensions.AsIs(anap[i])
It seems that you need gcc-4.0, and it would be helpful to specify your OS type and version.
Maybe this question will help you a bit: Installing GCC to Mac OS X Leopard without installing Xcode
Update
I'm a Windows user, so I can't test your setup, but a quick google pointed to some more links:
http://hardlifeofapo.com/psycopg2-and-postgresql-9-1-on-snow-leopard/
Cannot install psycopg2 on OSX 10.6.7 with XCode4
I encountered the No module named psycopg2.extensions error when trying to run pip2 install psycopg2 on a Mac running Mavericks (10.9). I don't think my stack trace included a message about gcc, and it also included a hint:
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
I looked for the pg_config file in my Postgres install and added the folder containing it to my path: /Applications/Postgres.app/Contents/Versions/9.4/bin. Your path may be different, especially if you have a different version of Postgres installed - I would just poke around until you find the bin/ folder. After doing this, the installation worked.
try this: sudo pip install -i https://testpypi.python.org/pypi psycopg2==2.7b2
.. this is especially helpful if you're running into egg error
on aws ec2 instances if you run into gcc error; try this
1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2. sudo su -
3. sudo pip install psycopg2
This one worked for me
python manage.py migrate
I had such problem when trying to run python script as a sudo, while psycopg2 was installed via pip3 to my own user's directory.
I managed to resolve the issue for myself removing pip3 version, and just installing it via apt:
pip3 uninstall psycopg2
sudo apt install python3-psycopg2
you can install gcc for macos from https://github.com/kennethreitz/osx-gcc-installer
after instalation of gcc you'll be able to install psycopg with easy_install or with pip
Check if you have installed psycopg2 if not
sudo apt-get install psycopg2
Install the dependencies.
sudo apt-get build-dep python-psycopg2
These two commands should solve the problem.
This error raise because you not install postgres database in you project virtutal environment. you should run one of these command.
from a terminal you can you command for sudo.
sudo apt-get install build-dep python-psycopg2
for pip (pip basically work for python)
pip install psycopg2
or
pip3 install psycopg2-binary
i'm pretty sure it will work for you.