python mysql configuration problem - python

I'm trying to make django work on snow leopard. So far I've installed mysql 64 bit installed python 2.7 64 bit and installed django 1.2.1. Now I'm trying to install mysql-python-1.2.3; at the beginning I had problems because I hadn't installed the setup tool, having done that when try to install it by executing these command
python setup.py build
python setup.py install
here's what I got
running build
running build_py
creating build/lib.macosx-10.5-fat3-2.7
error: could not create 'build/lib.macosx-10.5-fat3-2.7': Permission denied
Any idea?
Am I doing something wrong?
Thanks
Mauro

You need to use sudo
sudo setup.py build
sudo setup.py install
You might just want to use sqlite.

At the risk of pointing out the obvious, you do not have permission to write to the build directory. Check and change the directory permissions (with the chmod command) or do the setup as an admin user.

Related

Python setup.py without root

I would like to install some Python module, namely the MATLAB Engine. MATLAB is installed globally under /usr/local/sw/matlab, so I change to the corresponding directory and then run setup.py as explained in the linked documentation. However, I am not root, so I added the --user flag, as documented by the official Python Docs.
So this is what I get:
> python setup.py install --user
running install
running build
running build_py
creating build
error: could not create 'build': Permission denied
Apparently it tries to build the module in the current directory, where I have no write access. I can sidestep this by running
python setup.py build --build-base=/path/to/temp/build/dir
But then I don't know how to install that. Also I cannot combine those 2 approaches as install does not recognize the --build-base option.
I furthermore tried to copy the whole matlabroot/extern/engines/python directory somewhere else and run python setup.py install --user there, but this yields
error: The installation of MATLAB is corrupted. Please reinstall MATLAB or contact Technical Support for assistance.
I guess it does not find the matlabroot anymore.
So how do I build and install some source located somewhere under /usr... without being root?
You can use Virtualenv or venv to deal with this kind of issues.
Edit: As we went a bit deeper into issue itself, we managed to figure out the answer.
If you wish to use virtual environment: python setup.py build --build-base="/path/to/directory_you_can_write_to" install --prefix="/path/to/virtualenv/" --user
If you wish to accomplish what #Feodoran asked for: python setup.py build --build-base="/path/to/directory_you_can_write_to" install --user
Useful links:
https://de.mathworks.com/help/matlab/matlab_external/install-matlab-engine-api-for-python-in-nondefault-locations.html
https://python.org/3.2/install

Why can't I install setuptools on my Centos 6 VPS?

I'm trying to install setuptools for Python2.7 on a Centos 6 VPS with Digital Ocean using this tutorial. When I reach the step where you "Intall setuptools using the Python we've installed (2.7.6)", I get this error:
[username#hotsname setuptools-1.4.2]$ python2.7 setup.py install
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/test-easy-install-1111.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/local/lib/python2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
https://pythonhosted.org/setuptools/easy_install.html
Please make the appropriate changes for your system and try again.
Now, I previously followed instructions on the same digital ocean community site to give the user executing the above root privileges. When I try to use sudo to do this task, I get:
[username#hostname setuptools-1.4.2]$ sudo python2.7 setup.py install
[sudo] password for username:
sudo: python2.7: command not found
So I'm a little confused. I feel like I'm probably missing something simple. Digital Ocena was unable to provide further support on this. I've worked with virtualenv for a long time and am familiar with what to do once I get it installed, I'm just stuck here as it's my first time setting up a Centos host. Can you tell what I'm missing?
Thank you!
Changing to root user did the trick. Thanks CasualDemon.
Nowadays, if you'd like to install setuptools & pip easily, you can run this file with your python interpreter:
get-pip.py
You made need administrator (root) privileges for installing it to your system python (e.g sudo python get-pip.py.
Afterwards you can upgrade pip and/or setuptools through e.g:
$ pip install -U setuptools
$ pip install -U pip
I recommend for most python development you only install setuptools, pip, and virtualenv as root (or purely virtualenv, if you're being conservative). After, you can use virtualenv virtual environments to create isolated python environments which don't need to install to the system python or affect its installed packages. That way no other python (and/or pip invocations) needs to be run as root.

Unable to install YAML for Python2.7 on my mac

I am trying to install YAML module (PyYAML3.10) for Python 2.7 on my mac. I get the foll error message:
$ python setup.py install
running install
running build
running build_py
running build_ext
running install_lib
creating /Library/Python/2.7/site-packages/yaml
error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied
Can anyone help me out with this?
Thanks!
It's a matter of permissions... Try with: sudo python setup.py install
The error is very clear:
error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied
You don't have permission to write to this directory. If you run setup.py using sudo, you'll run it with root privileges, which will let you install it:
sudo python setup.py install
You may want to look into something like macports, which gives you a convenient way of installing (and uninstalling, ugrading, etc) a variety of open source software. It includes packaged versions of the YAML module.
I would suggest that you use pip to install the package and virtualenv to make pip install packages as your user. This way you won't get anymore Permission denied messages. See this guide for learning more about virtualenv. It might seem a bit hard to grip at first but I promise you that the effort is well worth it.

Problems getting Django up and running on OSX

First, I'm following the tutorial on the Django Poll application on their site and have hit a few road blocks.
I've installed Python 2.7 and Django 1.3
Created a new project with
django-admin.py startproject myproject
I got mysql up and running and entered the credentials in settings.py
Then when I try to run
python manage.py syncdb
it puked ... http://pastie.org/2294709
Then when I installed Mysql-python
easy_install mysql-python
Success! ...
Searching for MySQL-python
Best match: MySQL-python 1.2.3
Adding MySQL-python 1.2.3 to easy-install.pth file
Using /Library/Python/2.6/site-packages
Processing dependencies for MySQL-python
Finished processing dependencies for MySQL-python
so I try again
python manage.py syncdb
Still pukes the same message as above
Am I missing Something?
jondavidjohn's comment is spot on: you will have no end of confusion with multiple versions of Python on the Mac. There are some things you can do to deal with this.
Stick with 2.6
Convert to Lion, which has 2.7
Add an alias to your shell environment to invoke version 2.7 with $ python. In my bash_profile, I have "alias python='/usr/local/bin/python'"
Be sure to set your PYTHONPATH variable to the site packages directory that corresponds to the version of Python that you're using, such as PYTHONPATH=/usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages
Make sure you know which version of easy_install is operative; many module problems arise from assuming that easy_install will use the same site-packages version for everything. Not true always. Every different Python bin directory has its own version of easy_install (or pip, by preference) which will use the corresponding site packages directory.
Don't try to run Django under Python 3.x
Don't try to get rid of the OS version of Python; it will break your installation because software update sometimes relies on it.
Once you're past this hurdle, there are some other parts of getting the sample poll app in Django to run that I had problems with, so I put my experience at https://github.com/technocrat/Writing-your-first-Django-app
You need to install and use a version of easy_install for your Python 2.7. You are using the version for the system Python 2.6. Follow the instructions here to install Distribute using python2.7 to launch python. Then use easy_install-2.7 to install mysql-python.

Django unable to find MySQLdb python module

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/

Categories