django mysql-client or mysql-db error - django

I am facing these errors when I am running the python manage.py runserver
Also i have tried:
1.pip install MySQL-python
2.pip install mysql-python
but nothing worked.I need help
Errors i am getting

I faced the same problem time ago.. I solved it doing this:
1) for Windows:
$ pip3 install mysqlclient
2) for Linux:
$ pip3 install mysqlclient
if fails with "mysql_config not found" you have to do (only linux):
$ apt-get install libmysqlclient-dev
Of course, use pip instead of pip3 if you're working with python2.7

Related

Error when i install pip in python2.7 in window

i am try to install pip for Django in python2.7(window7) when i try to run
python get-pip.py i get error in cmd.
python get-pip.py
could not find a version that satisfies the requirement pip no matching distribution found for pip
Upgrade to a newer version of python.
Refer: https://github.com/pypa/pip/issues/5357

installation of pipenv causes pip3 unusable

I installed pipenv using
$ pip3 install pipenv which gives me the error ImportError: cannot import name 'main'
in order to solve this error I followed these instruction sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
now pip3 command is working on terminal.
now I install pipenv using pip3 install pipenv
it installed succesfully but when i tried to execute pipenv on termnal it gave me
pipenv: command not found at this point pip3 also gives ImportError: cannot import name 'main' error in order to solve this i followed these instruction
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
at this, point pipenv is working but pip3 is not working .
How can I make both pip3 and pipenv work at the same time?
Also, it seems that I have messed up my pipenv setting now the virtual environment is created by default at /home/sysadmin
instead of the location i used to create virtual environment /home/sysadmin/Desktop/helloworld
The problem is due to overwriting the system-managed version of pip when installing pipenv. You performed the correct first step by getting your system-managed pip back in order:
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
Once that is done, it is important to note that pipenv will likely not be able to be installed at the global level due to the pip conflict. You can install pipenv at the user level:
pip install --user pipenv
This should install pipenv at a user-level in /home/username/.local so that it does not conflict with the global version of pip. In my case, that still did not work after running the '--user' switch, so I ran the longer 'fix what I screwed up' command once more to prep the environment:
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
and then did the following:
mkdir /home/username/.local ... if it doesn't already exist
export PYTHONUSERBASE=/home/username/.local
Make sure the export took (bit me once during this process):
echo $PYTHONUSERBASE
Then, I ran the pip install --user pipenv and all was well. I could then run pipenv from the CLI and it did not overwrite the global/system-managed pip module. Of course, this is specific to the user so you want to make sure you install pipenv this way while working as the user you wish to use pipenv.
References:
https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name
https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv
https://pip.pypa.io/en/stable/user_guide/#user-installs

pip command by default using python 3...how to change it to python 2?

I am using macOS Sierra 10.12 and after I upgraded my OS I can no longer install packages for python 3 using pip. Before I used to use pip for python2 and pip3 for python 3 as I have both versions of Python. But now I can no longer use pip to install libraries for python2.
Can anyone help me how can I change my default pip installer to python2? So that I can just use pip install in order to install for python 2.
For your information - when I only type python on terminal it says my default is python 2.7.
on running
which pip
I got /usr/local/bin/pip
Which meant it was pointing to pip2
To change default pip to pip3, run
sudo ln -s /usr/local/bin/pip3 /usr/local/bin/pip
install pip for Python2.7 with easy_install:
sudo easy_install-2.7 pip
now you can use pip for the same specific version of Python:
sudo pip2.7 install BeautifulSoup

Django 1.9 Compiling Error

I created a virtualenv and downloaded Django with the below commands:
virtualenv tester
source tester/bin/activate
pip install django
and below is the response:
Downloading/unpacking django
Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Compiling /home/romaan/workspacepy/tester/build/django/django/conf/app_template/apps.py ...
File "/home/romaan/workspacepy/tester/build/django/django/conf/app_template/apps.py", line 4
class {{ camel_case_app_name }}Config(AppConfig):
^
SyntaxError: invalid syntax
Compiling /home/romaan/workspacepy/tester/build/django/django/conf/app_template/models.py ...
File "/home/romaan/workspacepy/tester/build/django/django/conf/app_template/models.py", line 1
{{ unicode_literals }}from django.db import models
^
SyntaxError: invalid syntax
Successfully installed django
Please help me to get rid of this error. All though it says Successfully installed django, I am keen on understanding and getting rid of this syntax error.
Or Should I just wait for the bug fix to happen?
This looks like the setuptools issue mentioned in the Django 1.9 release notes: https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-setuptools-5-5-x
Try to run pip install --upgrade pip before running pip install django
Those can't, and shouldn't, be fixed. Those are template files which are substituted at project creation time, and are not valid Python syntax. They shouldn't be compiled at install time but rather at project creation time.
These steps worked for me:
$ sudo python -m pip install --upgrade --force setuptools
$ sudo python -m pip install --upgrade --force pip
$ sudo pip install django==1.9
pip install -U pip ran fine but didn't fix my issue
I got the same message when I was trying pip install django.
I thought to try a previous version so I tried pip install
django-1.9.
It said "Real name of requirement Django-1.9 is django-503".
So pip install Django-503 worked fine for me.

Installing MySQL-python for Django

I've just learned how to use virtualenv and I installed Django 1.4.5. I'm assuming that the virtualenv created a clean slate for me to work on so with the Django 1.4.5 installed, I copied all my previous files into the virtualenv environment.
I tried to run the server but I get an error saying "no module named MySQLdb". I think this means that I forgot to install MySQL-python. I tried to install it via
pip install MySQL-python
But I get this error
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24 (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24 (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
----------------------------------------
Command python setup.py egg_info failed with error code 2 in /home/bradford/Development/Django/django_1.4.5/build/MySQL-python
Not quite sure how to go about fixing this problem =/ any help much appreciated!
I recently had exactly this issue (just not in relation to Django). In my case I am developing on Ubuntu 12.04 using the default pip and distribute versions, which are basically a little out of date for MySQL-python.
Because you are working in an isolated virtualenv, you can safely follow the suggested instruction without affecting your Python installation.
So you can...
workon your_virtualenv #activate your virtualenv, you do use virtualenvwrapper, right?
easy_install -U distribute #update distribute on your virtualenv
pip install MySQL-python #install your package
If for some reason upgrading distribute is not an option, you could try installing an older version of MySQL-python as follows (you'd have to check this version is compatible with your version of Django):
pip install MySQL-python==x.y.z #where x.y.z is the version you want
Spent an hour looking through stackoverflow. Evntually found answer in the other question. This is what saved me:
sudo apt-get install libmysqlclient-dev
mysql_config goes with the package.
When doing in a virtualenv :
pip install MySQL-python
I got
EnvironmentError: mysql_config not found
To install mysql_config, as Artem Fedosov said, first install
sudo apt-get install libmysqlclient-dev
then everything works fine in virtualenv
MySQL driver for Python (mysql-python) needs libmysqlclient-dev. You can get it with:
sudo apt-get update
sudo apt-get install libmysqlclient-dev
If python-dev is not installed, you may have to install it too:
sudo apt-get install python-dev
Now you can install MySQL driver:
pip install mysql-python
Here is a more detailed documentation for MySQL in Django:
http://codex.themedelta.com/how-to-install-django-with-mysql-in-a-virtualenv-on-linux/
I had to do this:
pip install mysql-python
inside the virtualenv
The commands are always run in ubuntu:
easy_install -U distribute
later
sudo apt-get install libmysqlclient-dev
and finally
pip install MySQL-python
The suggested solutions didn't work out for me, because I still got compilation errors after running
`$ sudo apt-get install libmysqlclient-dev`
so I had to run
apt-get install python-dev
Then everything worked fine for me with
apt-get install python-dev
Try this:
Version Python 2.7
MySQL-python package, you should use either MySQL_python‑1.2.5‑cp27‑none‑win32.whl or
MySQL_python‑1.2.5‑cp27‑none‑win_amd64.whl depending on whether you have installed 32-bit or 64-bit Python.
pip install MySQL_python‑1.2.5‑cp27‑none‑win32.whl
if you are using mysqlclient package, then use
mysqlclient‑1.4.6‑cp27‑cp27m‑win32.whl or
mysqlclient‑1.4.6‑cp27‑cp27m‑win_amd64.whl
pip install mysqlclient‑1.4.6‑cp27‑cp27m‑win32.whl
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient