Version error after pip installing MySQL-python on OSX - python

I have successfully installed MySQL-python to my virtual environment, confirmed by the fact that PyCharm can import it. I am however getting this message:
ImportError: this is MySQLdb version (1, 2, 4, 'beta', 4), but _mysql is version (1, 2, 5, 'final', 1)
My installation method has been:
Activate my venv in the terminal
export PATH=$PATH:/usr/local/mysql/bin
export CFLAGS=-Qunused-arguments export CPPFLAGS=-Qunused-arguments
pip install MySQL-python
Which returns a successful build. I really don't understand what the problem is, is pip serving me a corrupted directory?
I tried resolving this by googling and the likes to no avail. I then tried downloading version 1.2.4b4 from sourceforge and built it within the venv. This gives me the following error:
ld: warning: ignoring file /usr/local/Cellar/mysql/5.6.19/lib/libmysqlclient_r.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/mysql/5.6.19/lib/libmysqlclient_r.dylib
I have run file $(which ) on mysql and python, returning a 64 bit build for mysql and both a 32 and 64 bit build for python.
I really have no idea what to do next, I would really appreciate some help, let me know if I've missed something! Thank you
EDIT:
I pip uninstalled MySQL-python and tried again with this zip: https://pypi.python.org/pypi/MySQL-python/1.2.5
pip install -Iv https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Which gave me the same error as before, stating MySQLdb is version 1.2.4b4 but _mysql is 1.2.5. This leads me to believe I might have a lingering version of MySQL-python that isn't being uninstalled. How would I go about testing this? Thanks!

A couple of common potential issues:
make sure your path is right and that pip and python refer to the same interpreter. Virtual environments are best activated by doing source activate <NAME> or prepending them to the path instead of appending.
I had multiple issues with MySqlSB and stack overflow is full of questions about it. All my problems went away when I switched to pymysql, whose API is fully compatible with mysqldb. Even better, there is a method install_as_MySQLdb() which makes pymysql appear exactly like mysqldb, so all packages the expect the latter work with the former.
The procedure that I use to get set up on OSX is:
get rid of all Python installations (system python, home-brew, etc)
brew install mysql gcc. gcc is in case you want to compile c/fortran extensions to python modules.
Watch for permission errors- always run brew doctor
install anaconda
set up a virtual environment conda create -n <NAME> python=3.4
activate virtual environment source activate <NAME>
install required packages, trying conda first and pip if the package isn't there. For example, I always do conda install numpy so I don't have to compile it myself, and I do pip install pymysql

Thanks for the above answer, good advice for future troubleshooters. I managed to solve this by re-installing the 1.2.5 build and restarting my compiler.
In other words, the method I outlined above should work. For future reference make sure your bin/activate and bin/pip have their paths set to your venv and not someone else on your developer team

Related

CQLSH ImportError: cannot import name ensure_str

I have installed Cassandra database on my CentOs system. after that, I tried to install the Cqlsh package using this command sudo yum install cqlsh and it has been installed successfully. but when I tried to run cqlsh from the terminal, the following error appears:
ImportError: cannot import name ensure_str
somewhere in the code, it tries to load a library named six that contains ensure_str. the error does not say that it can not find a module named six, the python interpreter can find the library but can not import it!
I have tried googling but none of the solutions worked for me.
after a few hours of googling and struggling with the code, finally, I find out the solution. and I'm going to share it with others.
apparently, the problem is the new version of six (v=1.7.3) which is not compatible with my system. However, Cassandra copies the last version of six into the following path:
/usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip
then cqlsh try to force the python interpreter to import the library from this path by adding the following lines to the code.
third_parties = ('futures-', 'six-', 'geomet-')
for lib in third_parties:
lib_zip = find_zip(lib)
if lib_zip:
sys.path.insert(0, lib_zip)
no matter if you have another version of six installed on your system, it always tries to import the library from the Cassandra folder.
So, I have just deleted these lines from cqlsh file using this command:
vim /usr/bin/cqlsh
Then I try to install the last compatible version on six using this command:
yum install six
That's it! problem solved and now I'm using cqlsh without any problem.
I hope it helps others.
We've had reports of this being a problem on CentOS specifically with version 6.7 but it possibly affects the 7.x releases too.
It appears that the wrong Python is getting called. This isn't strictly a Cassandra issue but a problem with the Python on the machine. You can verify which Python gets run with:
$ which python
As a workaround, you should be able to run cqlsh using the system Python as follows:
$ /usr/local/bin/python /usr/bin/cqlsh
Cheers!
Use pip3 to install or upgrade to the current six.
Edit a copy of cqlsh. Change
third_parties = ('futures-', 'six-', 'geomet-')
to
third_parties = ('futures-', 'geomet-')
Not proud, but it worked.
Used pip3 to install, and found this issue as well.
For me, removing six dependencies from /usr/lib/python3/dist-packages was the only thing that worked.
rm six-1.11.0.egg-info and rm -r six-1.11.0.egg-info
I couldn't uninstall it with pip3, so manual removal was the way to go, followed by a pip3 install six
Once that was back in place, cqlsh ran without issue.
The previous answers didn't work for me, I had to delete the Cassandra included six package, and then cqlsh used the system-wide package.
mv /usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip /usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip.bak
Maybe an older version of Cassandra installed, and a newer version of cqlsh?
https://community.datastax.com/questions/12085/unable-to-connect-to-cqlsh.html

multiple environment coremltools installation

Trying to install coremltools. I installed using pip but that is not the most recent version and I have run into a bug that was solved 4 days so I must build from source. I'm on a Mac virtual desktop(windows user) and I tried cmake, but since there are multiple pythons it keeps trying to install to python 3.7 when I need it to install for python 2.7.10. The github suggest doing this:
cmake . -DPYTHON=$(which python) -DPYTHON_CONFIG=$(which python-config)
.. however as someone who doesn't use cmake for package installs I'm unsure of the correct syntax could someone give me an example statement to go off of, I would really appreciate it. Thanks
You can install it without building it manually:
pip install https://github.com/apple/coremltools/archive/master.zip
You can replace "master" with any branch or tag names.
EDIT: To update an existing install add the -U flag. Or uninstall previous installations.

installed pip package not found

I was just given a new mac and after installing pip and lcc through pip I get a command not found error when running lcc run.
When running help("modules") inside of python I can see the lcc package there.
the same goes for pip freeze
pip freeze | grep lemon
lemoncheesecake==0.15.2
I'm running out of ideas.....
maybe I messed up the pip installation because I did it first with:
python get-pip.py
and then with
sudo easy_install pip
how do I fix this?
this is my echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Thanks
From what you're saying it seems that your python installation is not quite right, and Mac's version of python is also not quite right by default, you can read more about it here: http://docs.python-guide.org/en/latest/starting/install/osx/#doing-it-right
Also, I would highly advise that when you get a brand new Mac and plan to do some development work as a rule of thumb follow these steps:
Install xcode
Install Homebrew
Then you can install anything else you want.
I think the problem is due to the fact you have more than one version of python installed. Package installed by pip are visible to one version, but not to the other. I think this issue is quite common, and has already been answered (for example) here:
Too many different Python versions on my system and causing problems
To check that this is the case:
pip show Icc
should tell you where Icc was installed.
import sys
print sys.path
should tell where python looks for modules.

How to install Numpy & pip3 for python3.x when they were installed in python2.7? Using Conda?

I want to write program in python3 (3.5), hence I installed python3 next to the pre-installed python2 (2.7) on Mac OS X El Captian.
Since my terminal runs python2.7 by default and Numpy is already installed for it, I put alias python=python3 and expected to be able to install Numpy for python3. when I type pip install numpy. This was the generated message:
Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
I also noticed that I have no pip3 even though I am using python3: python --version returned Python 3.5.2, but pip3 install numpy got me -bash: pip3: command not found.
So my questions are:
1) How to install Numpy for python3.x when Numpy is installed on python2.x?
2) How to get pip3?
3) Is it better to use virtual environments, such as Conda, instead of juggling between python2 and python3 on the system?
Thank you from a total n00b
------------------- Update -------------------
Reinstalling python3 also fixed another problem in my case.
When I ran brew doctor, one of the warning message I got was:
Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run brew link on these: python –
This is a result of me running brew unlink python in order to fix
"Python quit unexpectedly"
when I launch Vim and also
"The ycmd server SHUT DOWN"
Both seem to relate to the YouCompleteMe autocomplete plugin which I downloaded for Python.
I got my idea of removing symlinks from here and here
However, Homebrew evidently did not like the absence of those 39 symlinks.
After uninstall (brew uninstall python3) and then re-install python3 (brew install python3) as Toby suggested, Homebrew gave me
You can install Python packages with
pip3 install <package>
Then when I pip3 install numpy and pip3 install scipy, both executed successfully.
To my surprise, symlinks created during Python installation used to cause aforementioned error messages for Python and YouCompleteMe, but now I open python files using Vim without crash from a fresh Python installation, which definitely created the symlinks.
------------------- Update2 ------------------
After re-installing Anaconda2, the same YouCompleteMe error came back. I suspect Anaconda messed up symlinks.
I would recommend using the Anaconda Python distribution.
The main reasons are as such:
You will have a Python distribution that comes with numpy and the rest of the Scientific Python stack.
The Anaconda Python will be installed under your home directory, with no need for sudo-ing to install other packages.
conda install [put_packagename_here] works alongside pip install [put_packagename_here]; conda install is much 'cleaner' (IMHO, differing opinions are welcome).
If you have a Python 3 environment as your default, then pip works out-of-the-box without needing to remember to do pip3.
conda environments are easier to manage than virtualenv environments, in my opinion. And yes, you can have Python 2 alongside Python 3.
I once messed up my system Python environment - the one that came with my Mac - and it broke iPhoto (back in the day). Since then, I became convinced of needing separate, atomic environments for different projects.
I've detailed more reasons in a personal blog post.
Other distributions, of course, are all good, provided they give you what you need :).
The simplest way on a Mac is with Homebrew:
http://brew.sh/
Install Homebrew, then run:
brew install python3 pip3
Edit --
Python3 includes pip3, but Homebrew occasionally has trouble linking to the correct versions, depending on what has been installed. Running the following command:
brew doctor
And if you see errors relating to python or unlinked kegs, try running:
brew uninstall python python3
And reinstalling after checking brew doctor.
https://unix.stackexchange.com/questions/233519/pip3-linked-to-python-framework-instead-of-homebrew-usr-local-bin

MySQLdb and Python ImportError

I cannot for the life of me figure this one out. I've been searching around the web all day and all the resources seem terribly out dated. From what I can tell getting MySQLdb and Python to play nice together is fairly difficult. I've gotten about as far as I can on this, and I'm not sure how to proceed going forward.
First off, I am running Python 2.7
The error I get when I try and run "import MySQLdb" in the live interpreter is this:
ImportError: this is MySQLdb version (1, 2, 2, 'final', 0), but _mysql is version (1, 2, 5, 'final', 1)
I also see the following error logs when I run "pip install mysql-python" however I'm not sure if thats jsut related to the version mis-match.
http://pastebin.com/hqVv6aPZ
I have a python project that has a dependency on MySQLdb and I've been trying to get the virtualenv that I'm running Python from to install the package properly. This is what I've done:
I've built MySQL from the source to ensure that I have a 64bit compatible version of MySQL on my machine. I used the --universal flag to ensure this.
I have verified that I am running a 64bit version of Python as well.
MySQL came from Homebrew
mysql-python came from pip
I can't for the life of me figure out what to do here. It seems like there is just a version mis-match between MySQLdb and _mysql on my machine. Is this the case? If so is the solution simply reinstalling an older version of MySQL? It appears that when I force pip to install version 1.2.5 of mysql-python it installs version 1.2.2 of MySQLdb, so i'm lost as to what to do here because I'm not sure what package from homebrew actually correlates to version 1.2.5 for _mysql.
EDIT -
sys.path
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python27.zip',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/plat-darwin',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/plat-mac',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/Extras/lib/python',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/lib-tk',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/lib-old',
'/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/adam.stark/virtualenvs/qa-automated-tests/lib/python2.7/site-packages'
Python --version says i'm on version 2.7.5. I've also set the pastebin to public. I'm just not sure what exactly is pertinent information within that dump, it spits back 16 errors.
The issue here ended up being a few things. As abarnert pointed out in the comments of the question, there was a mixing of the system python and the virtualenv python. To resolve this I had to change the project properties of the PyDev project to only point to the virtualenv python instance, then in the PyDev interpreter preferences I had to rebuild the PYTHONPATH.
After this was done, in the virtualenv I had to run the following code:
pip uninstall mysql-python
pip install mysql-python==1.2.5
This resolved all of the issues.
You can try this. Open terminal and type:
sudo apt-get remove python-mysqldb
sudo apt-get install python-dev libmysqlclient-dev
git clone https://github.com/farcepest/MySQLdb1.git
python setup.py build
sudo python setup.py install
It worked for me. I use Python 2
I had the same problem, produced for a different reason tho. I don't have root privileges on my working machine (part of the university infrastructure). I had to install MySQLdb locally by issuing
pip install --user MySQL-python (from this guide ). This produced the same
ImportError: this is MySQLdb version (1, 2, 3, 'final', 0), but _mysql is version (1, 2, 5, 'final', 1) mismatch. Installing version 1.2.5 didn't work.
What I did : uninstall from local and re-install version 1.2.3 as indicated by the error
pip install --user MySQL-python==1.2.3
Error disappeared.
do this and try again
pip uninstall mysqlclient

Categories

Resources