Installed Django from source (python setup.py install and such), installed MySQLdb from source (python setup.py build, python setup.py install). Using Python 2.4 which came installed on the OS (CentOS 5.5). Getting the following error message after launching the server:
Error loading MySQLdb module: No module named MySQLdb
The pythonpath the debug info provides includes
'/usr/lib/python2.4/site-packages'
and yet, if I ls that directory, I can plainly see
MySQL_python-1.2.3-py2.4-linux-i686.egg
Using the python interactive shell, I can type import MySQLdb and it produces no errors. This leads me to believe it's a Django pathing issue, but I haven't the slightest clue where to start looking as I'm new to both Django and python.
EDIT: And to be a bit more specific, everything is currently running as root. I haven't setup any users yet on the machine, so none exist other than root.
EDITx2: And to be even more specific, web server is Cherokee, and deploying using uWSGI. All installed from source.
Have you considered installing MySQLdb from python packages?
I would also recommend doing this with pip instead of easy_install.
First you can replace easy_install with pip:
easy_install pip
pip install pip --upgrade
And then install Django via PIP:
pip install MySQL-python
pip install Django
Typically easy_install is installed already (part of setuptools), while pip is much better. It offers uninstallation options too, and uses flat install directories instead of the EGG files magic. This might resolve some incompatibilities as well.
Did you try building the dependencies? This solved it for me on Ubuntu:
sudo apt-get build-dep python-mysqldb
pip install MySQLdb-python
What worked for me (Linux Mint):
sudo apt-get install libmysqlclient-dev (this was the key for me)
pip install mysql-python
pip install django
You can find out where Python is looking for it's libraries by invoking "python manage.py shell" from the directory base of your Django project. Then do:
import sys
import pprint
pprint.pprint(sys.path)
And you'll see where the python is pulling libraries from. Also try to do a "import mysql" to see if that's kicking out an error.
Finally, the pathing for the WSGI service is (likely) configured with the uWSGI setup in Cherokee - sorry, I don't know the details of that critter to make suggestions on how to determine where/how it's loading the library path.
I was having this same problem, but it was only an issue inside a virtualenv.
What I did to finally fix it was
workon [project_name]
pip uninstall django
pip install mysql-python
pip install django
So making sure you install mysql-python before django seems to work.
This is on a Ubuntu system and using virtualenv.
Try this if you are using
linux:- sudo apt-get install python-mysqldb
windows:- pip install python-mysqldb or
easy_install python-mysqldb
Hope this should work
This did the trick for me:
sudo apt-get install python-dev
pip install mysql-python
Solved my problem :)
in my case, Python was able to access mySQL, but Django (1.6) gave the error: "Error loading MySQLdb module: No module named MySQLdb"
I am on a Macbook OSX (Maverick), by the way.
When I tried to run
pip install mysql-python
I got an error during compilation : "clang: error: unknown argument: ‘-mno-fused-madd’ [-Wunused-command-line-argument-hard-error-in-future]."
The problem, it turns out, is an updated behavior of cc compiler with the new Xcode 5.1. When there is a parameter it doesn't recognize, considers it as a fatal error and quits. The solution to override this behavior can be found here:
http://bruteforce.gr/bypassing-clang-error-unknown-argument.html
This issue was the result of an incomplete/incorrect installation of the MySQL for Python adapter.
Specifically, I had to edit the path to the mysql_config file to point to /usr/local/mysql/bin/mysql_config.
Discussed in greater detail in this article:
http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/
Related
I have been stuck on a module not found error of python3.
I have a VM on Microsoft Azure, a Centos 7. Then I installed python3 and pip3, and some packages I needed. But there’s one package that I just couldn’t find after I installed it
sudo pip3 install --user stockstats
But whenever i wanted to run a python script using this package, there’s
ModuleNotFoundError: No module named 'stockstats'
What I tried:
pip3 show stockstats
As I really want to see where it was installed. It shows nothing. What it is supposed to do is like this:
Name: openpyxl
Version: 3.0.7
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
Home-page: https://openpyxl.readthedocs.io
Author: See AUTHORS
Author-email: charlie.clark#clark-consulting.eu
License: MIT
Location: /usr/local/lib/python3.6/site-packages
…
Then I guess it might be something wrong with the installed path, so I uninstalled the package, and then did
sudo pip3 install stockstats --install-option="--prefix=/usr/local/lib"
(I am just guessing if openpyxl is installed there then stockstats should be there too, as python imported openpyxl successfully)
That didn’t work as well, the error still persists.
*I didn’t use any package manager other than pip3.
** some irregularities occurred when I was trying to use python3(see this post). It was resolved, but I am not sure if the error in this post is related to that.
Any help or hint would be appreciated ;)
Thanks all for the prompt reply.
After Guo Lei’s comment, I tried downloading the tar ball for this package and installing it myself without pip, which eventually told me what exactly happened: a module named int-date, required by stockstats, was not installed in the python library directory. After I installed it in the proper directory, the issue is resolved.
As Danila Vershinin and phd had pointed out, I really shouldn’t run pip as root, and that is the source of issue(curiously, however, that only one particular module required by stockstats is installed in /root/.local/lib/. All others are in the right place, maybe I added the prefix flag without remembering it...?)
Still, I am not sure, I ran pip using sudo because I received permission denied errors repeatedly — so should I use something like sudo --user? Or sth else?
This works for me.
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple stockstats
or
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install stockstats
You can visit This website for Installing pip in centos 7 Pip Install In Centos 7
for maybe some errors in installing pip.
reinstall python.
check that the module name is correctly typed
install stockstats in pip like "pip install stockstats" (getten from pypi.com)
I use Mac and I am new to Flask. I first wanted to install virtualenv via command-line. This is the error I get:
$ brew install Flask
Error: No available formula with the name "flask"
==> Searching for a previously deleted formula... Error: No previously deleted formula found.
==> Searching for similarly named formulae... Error: No similarly named formulae found.
==> Searching taps... Error: No formulae found in taps.
When I tried to install Flask via pip, it gave me this error:
$ pip install Flask
/usr/local/bin/pip: line 1: syntax error near unexpected token `('
/usr/local/bin/pip: line 1: `var freckle = require('freckle')'
I just wanted to start with Flask, I'm completely new to this framework.
I often get this error when I try to install a module of Python. I use Python 2.7.10.
Thanks in regard. (stop deleting this. I am a friendly person)
So, the only thing that actually worked, was:
pip3 install virtualenv
pip3 install Flask
Thanks to everyone, who helped out.
Try the following:
brew update && brew install flask
The problem might be that the directory is not up to date. The above command should clear that. Cheers.
So, you already have virtualenv installed.
Now what you need to do is create and activate a virtualenv for your project.
First, go to your project folder and then do this:
virtualenv project_name
Activate it:
. project_name/bin/activate
And install flask:
pip install Flask
Hope it helps. Read more about it here
The issue you have is caused by a npm package which exposes an executable with the name pip.
To install python packages using pip, run:
python -m pip install <package name>
In your case:
python -m pip install Flask
I'm trying to install scrapy-deltafetch in a virtual-environment (as described here) on my new raspberry pi 3 with Raspbian.
When I'm running pip install scrapy-deltafetch in my virtualenv, I'm getting something like this:
python setup.py egg_info:
Can't find a local Berkeley DB installation
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ib6d93/bsddb3/
However when I'm running sudo pip install scrapy-deltafetch outside of my virtual-environment everything works fine.
Does anybody has an idea of how to install scrapy-deltafetch in the virtualenvironment?
Your system is missing Berkeley DB, which is used by DeltaFetch to store requests data.
So, first install Berkeley DB in your system (found this tutorial in a quick search).
After that, you have to install the bsddb3 Python package (you can follow the instructions from this answer).
Edit (2020):
This should work:
$ sudo apt install libdb-dev
$ pip install bsddb3
In case of my Ubuntu 18.04 missing system library is called libdb-dev.
> sudo apt-get install libdb-dev
This fixed the problem for me.
I'm using the most recent versions of all software (Django, Python, virtualenv, MySQLdb) and I can't get this to work. When I run "import MySQLdb" in the python prompt from outside of the virtualenv, it works, inside it says "ImportError: No module named MySQLdb".
I'm trying to learn Python and Linux web development. I know that it's easiest to use SQLLite, but I want to learn how to develop larger-scale applications comparable to what I can do in .NET. I've read every blog post on Google and every post here on StackOverflow and they all suggest that I run "sudo pip install mysql-python" but it just says "Requirement already satisfied: mysql-python in /usr/lib/pymodules/python2.7"
Any help would be appreciated! I'm stuck over here and don't want to throw in the towel and just go back to doing this on Microsoft technologies because I can't even get a basic dev environment up and running.
If you have created the virtualenv with the --no-site-packages switch (the default), then system-wide installed additions such as MySQLdb are not included in the virtual environment packages.
You need to install MySQLdb with the pip command installed with the virtualenv. Either activate the virtualenv with the bin/activate script, or use bin/pip from within the virtualenv to install the MySQLdb library locally as well.
Alternatively, create a new virtualenv with system site-packages included by using the --system-site-package switch.
source $ENV_PATH/bin/activate
pip uninstall MySQL-python
pip install MySQL-python
this worked for me.
I went through same problem, but using pip from virtualenv didn't solve the problem as I got this error
error: could not delete '/Library/Python/2.7/site-packages/_mysql.so': Permission denied
Earlier I had installed the package by sudo pip install mysql-python
To solve, copy files /Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7.egg-info and /Library/Python/2.7/site-packages/_mysql* to ~/v/lib/python-2.7/site-packages and include /usr/local/mysql/lib in DYLD_LIBRARY_PATH env variable.
For the second step I am doing export DYLD_LIBRARY_PATH=/usr/local/mysql/lib in ~/.profile
Presently, I'm attempting to configure Django for use on a project, and am encountering a persistent error when I try to run python manage.py syncdb.
File "/x/x/x/x/x/x/base.py", line 23, in ?
raise ImproperlyConfigured("Error loading psycopg module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
The other discussions of a similar problem that I have found both here and on other sites ended up being solved by the user downloading and installing psycopg, but unless I'm missing something critical, I've done that several times. I downloaded the tarball, unpacked it on my server, ran python setup.py build and python setup.py install with a --prefix directing it to my existing Python Path...I can go and navigate to the folder and see the various psycopg files, but for whatever reason, when I try to get my new project to sync up with the database, it cannot find psycopg and, as a result, won't talk to the db.
Notes: hostmonster.com account, have tried multiple release versions of psycopg2.
I had the error as well; although psycopg2 was installed on my system using apt-get, my virtualenv couldn't find it:
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
It was fixed by doing a pip install psycopg2-binary inside the virtualenv (or pip install psycopg2 for <2.8 psycopg2 versions).
type pip install psycopg2-binary inside the virtualenv worked for me
I had this problem on a virtualenv in Ubuntu 18.4.
I solved it by installing psycopg2 v2.7.4:
pip install psycopg2==2.7.4
Try to use this:
sudo apt-get install python-psycopg2
On MacOS, psycopgy2 v2.8.4 and its binary isn't compatible with python 3.8 yet.
Downgrade to python 3.7. All works.
1- On mac (outside venv), Uninstall 3.8 and then install 3.7 using instructions: https://www.youtube.com/watch?v=X2VXCEfIgC0
2- Go to your django project main folder, delete 'venv' folder and 'manage.py'
3- Install new venv using python 3.7. command: python3 -m venv ./venv
4- Run venv. Command: source ./venv/bin/activate
5- Install django in this new venv again. Command: pip3 install django
This will create 'django-admin' under ./venv/bin/ and the django libraries.
6- Create manage.py like you would do for a new project again. Command: django-admin startproject <project folder> . (notice the '.' in end)
The command wont run as previous already exists. So before doing so, rename it to _temp and after running the command which creates a new folder, copy _temp contents to the new . Delete _temp.
7-Run: pip3 install psycopg2
and: pip3 install psycopg2-binary
(If you get an error pg_config executable not found error then run under venv, run following command before installing psycopg again:
export PATH=“/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH)
You try to load psycopg, not psycopg2.
Make sure that ENGINE is set to django.db.backends.postgresql_psycopg2 in the settings.py of your project:
'ENGINE': 'django.db.backends.postgresql_psycopg2'
May be problem is: 32bit version of Python cannot load a 64bit version of psycopg2.
I was also receiving similar error, it simply means that it is unable to find the "psycopg2" package/module.
I resolved it simply by installing it in my environment using the command:
pip install psycopg2
I hope this command will solve your problem (tested on ubuntu)
pip install psycopg2-binary
I had this problem inside a python virtual environment (virtualenv), copying the library into the site-package of the environment from the system site packages solved the problem.
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.7/dist-packages/psycopg2'
Consider using the --user option or check the permissions.
if the above error shows then, please try installing with:
pip install psycopg2-binary --user
Then it finally works. There is no need to edit on DATABASE ENGINE.
python -m pip install psycopg2
Run the below command in Command Line Prompt
pip install psycopg2
This will install psycopg2 and resolve the issue.
First:
pip uninstall psycopg2
Then, load the direct file from http://www.stickpeople.com/projects/python/win-psycopg/
file name : = psycopg2-2.6.2.win-amd64-py2.7-pg9.5.3-release.exe
As per your requirement, and then copy this downloaded file to env folder and do this:
easy_install psycopg2-2.6.2.win-amd64-py2.7-pg9.5.3-release.exe(your file name)
This will copy required files.
It can happen if you don't have psycopg2 installed already.
I had this problem with the virtualenv, I simply installed psycopg2 and it is working fine. No need to edit the db configurations.
pip install psycopg2
This Problem can be of any reason -
You have downloaded the wrong version of pyscog2 that doesn't support the current version of the Django.
You might have placed the pyscopg2 in the wrong directory.
You might have downloaded the pyscopg2 without the virtual environment and then activated post-install so it may be showing error.
Bad configuration of the virtual environment in manage.py leads to the error.
See the proper configuration it may be taking pyscopg2 from the root folder rather than the virtual environment.
sudo apt-get install python3-psycopg2
Worked on Ubuntu 20.04, python 3.10.4, Django 4.1.