I am trying to install MySQLdb package. I found the source code here.
I did the following:
gunzip MySQL-python-1.2.3c1.tar.gz
tar xvf MySQL-python-1.2.3c1.tar
cd MySQL-python-1.2.3c1
python setup.py build
As the result I got the following:
Traceback (most recent call last):
File "setup.py", line 5, in ?
from setuptools import setup, Extension
ImportError: No module named setuptools
Does anybody knows how to solve this problem?
By the way, if I am able to do the described step, I will need to do the following:
sudo python setup.py install
And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?
Thank you.
After trying many suggestions, simply using sudo apt-get install python-mysqldb worked for me.
More info:
Getting "Error loading MySQLdb module: No module named MySQLdb" - have tried previously posted solutions
If MySQLdb's now distributed in a way that requires setuptools, your choices are either to download the latter (e.g. from here) or refactor MySQLdb's setup.py to bypass setuptools (maybe just importing setup and Extension from plain distutils instead might work, but you may also need to edit some of the setup_*.py files in the same directory).
Depending on how your site's Python installation is configured, installing extensions for your own individual use without requiring sysadm rights may be hard, but it's never truly impossible if you have shell access. You'll need to tweak your Python's sys.path to start with a directory of your own that's your personal equivalent of the system-wide site pacages directory, e.g. by setting PYTHONPATH persistently in your own environment, and then manually place in said personal directory what normal installs would normally place in site-packages (and/or subdirectories thereof).
I resolved this issue on centos5.4 by running the following command to install setuptools
yum install python-setuptools
I hope that helps.
This was sort of tricky for me too, I did the following which worked pretty well.
Download the appropriate Python .egg for setuptools (ie, for Python 2.6, you can get it here. Grab the correct one from the PyPI site here.)
chmod the egg to be executable: chmod a+x [egg] (ie, for Python 2.6, chmod a+x setuptools-0.6c9-py2.6.egg)
Run ./[egg] (ie, for Python 2.6, ./setuptools-0.6c9-py2.6.egg)
Not sure if you'll need to use sudo if you're just installing it for you current user. You'd definitely need it to install it for all users.
#main:
$ su
$ yum install MySQL-python
and it will be installed (MySQLdb).
#!/usr/bin/env python
import os
import sys
from **distutils.core** import setup, Extension
if sys.version_info < (2, 3):
raise Error("Python-2.3 or newer is required")
if os.name == "posix":
from setup_posix import get_config
else: # assume windows
from setup_windows import get_config
metadata, options = get_config()
metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)]
metadata['long_description'] = metadata['long_description'].replace(r'\n', '')
setup(**metadata)
For Python 2.7, one can easily install using this
apt-get install python2.7-mysqldb
Also, you can see the build dependencies in the file setup.cfg
I am experiencing the same problem right now. According to this post you need to have a C Compiler or GCC. I'll try to fix the problem by installing C compiler. I'll inform you if it works (we'll I guess you don't need it anymore, but I'll post the result anyway) :)
well installing C compiler or GCC didn't work but I found a way to successfully install mysqldb package
kindly follow Mike schrieb's (Thanks to him) instructions here . In my case, I used setuptools-0.6c11-py2.7.egg and setuptools-0.6c11 . Then download the executable file here then install that file. hope it helps :)
When you need to install modules in Linux/Unix and you lack sudo / admin rights, one simple way around it is to use the user scheme installation, basically run
"python setup.py install --user" from the command line in the folder of the module / library to be installed
(see http://docs.python.org/install/index.html for further details)
Related
I try to install python utility:
pip install utility
but the module is not found after installation.
I tried unsuccessfully to set up permissions:
sudo chmod -R a+rX /usr/local/lib/python2.7/site-packages/
Then I realized after uninstall /install utility that pip shows a warning during the installation:
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
I guess that could be my issue. How can I get through that?
EDIT
The comments and answer was helpful to solve the issue. I was trying to import the "utility" file from this audio toolbox while there is an other python module named "utility" which does not contain any function.
As Peter Wood noted in the comments, it looks like that package (https://pypi.python.org/pypi/utility/1.0) isn't actually set up to install anything. I'm not sure what you wanted to use it for, but as far as I can tell, the utility package is really just a single python file which you could just download from https://bitbucket.org/tmthyjames/utilitybelt/raw/c0a9dc8acd7f4a55a10abb6fd9ef2630d171b3ea/utilitybelt.py (if that link doesn't work, https://bitbucket.org/tmthyjames/utilitybelt.git , click source, and then click raw)
I have written a program in Python which was done on windows. And in the windows test environment worked fine. Now I am setting up a linux server to internally host the program. I have installed all the dependencies etc from a generated requirements file but when I run it I come on a problem,
ImportError: No Module Named 'pysqlite2'.
I have extensively googled this issue and have not found a solution. Can anyone tell me how to fix this problem from code below? I cannot upload an image due to reputation isnt high enough. Any help would be greatly appreciated. If any other information is needed just comment and I will upload.
File "/home/ryan/python_p/venv/lib/python3.4/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 334, in dbapi
from pysqlite2 import dbapi2 as sqlite
ImportError: No Module named 'pysqlite2'
As far as I understand it sqlite either is not compatible or has compatibility issues?
Another issue that I think is directly related is when inside the virtual environment and I try pip3.4 install pysqlite i get
SyntaxError: Missing Parenthesis in call to 'Print
Its suggests install Sphinx which I did but did not cure.
I think these two issues are directly related and by curing ine should be able to cure the other.
You could probably just use sqlite3 which is now part of the standard library and should work exactly the same as pysqlite2 does. You can try to modify the file mentioned from:
from pysqlite2 import dbapi2 as sqlite
to
from sqlite3 import dbapi2 as sqlite
You can do the below changes to make your jupyter notebook work
Replace the file “C:\Windows\System32\sqlite3.dll”
by “C:\Users\username\anaconda3\Library\bin\sqlite3.dll”
This will make jupyter notebook work
Try pip search sqlite, you may find many candidates. Pick something like this one:
pip install pysqlite
For people on CentOS 6 and Python 2.6:
Executing pip install pysqlite directly would result in a gcc error, you would have to yum install sqlite-devel first, before installing pysqlite.
After that, ImportError may still persist, if you are using a Python version different from the Python 2.6 that's shipped with CentOS 6. The error message I got is like:
ImportError: /usr/local/lib/python2.7/site-packages/pysqlite2/_sqlite.so: undefined symbol: sqlite3_stmt_readonly
This is a linking issue, copying below compiled library files from old Py2.6 directory to Py2.7 solved my problem, as inspired by this Github discussion.
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/
I faced this issue with multiple python dependent package while setup, specifically while installing jupyter notebook in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.
Error I got:
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I resolved it by --enable-loadable-sqlite-extensions=yes
1.) First find your python or python version you used for creating virtual env. I have used python3.8
e.g
$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config python
$ cd /usr/bin
$ls
python3.8
python3.8-config
Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version
ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes
OR
ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions
Now, create your virtual env using that python version
e.g
Go the folder where you want to create the virtual env
$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate
Its done, now you can install packages
A lot of software packages require users of the system to install a set of dependencies first before they can use the software. (This is a general question not specific to python, but I'll speak in context of python.). Can't we make the python module install its own dependencies before executing the code if the dependencies are not already installed. This should be doable with the help of system or subprocess calls but I rarely see people doing this.
For example lets say lib is a python library that needs to be used in the python file main.py:
import os
try:
import lib
except:
os.system('pip install pdir')
import lib
# Can make use of lib now
Is there anything potentially wrong with this approach? Could doing something like this cause problems for big projects?
Note: The advantage here is that a user using the file does not have to install the dependencies separately, he can simply run python main.py. And the second thing that I realize is that such approach makes sense only when virtualenv is being used.
You should never do this - pip doesn't have dependency resolution so there's no guarantee that you'll get a certain version. Dependencies should be installed using setup.py, requirements.txt or a different approach.
You also shouldn't need user permissions or sudo to install the packages just for running the code. The user should be aware of the packages that are needed for installing your package as they may come from PyPI or the OS's package system or an internal company PyPI mirror - and silently installing dependencies is not a good idea in that case.
You could always consider using a more advanced print statement to inform the user.
try:
import ConfigParser
except ImportError as err:
print '\n'.join([i + ''.join(str(err).split(' ')[-1:]) for i in ['$ pip install ', '$ easy_install ']])
You can recommend them installing the missing package this way.
$ pip install ConfigParser
$ easy_install ConfigParser
Additionally you could consider having a ImportError be reason to recommend the user to run their ./setup.py or ./INSTALL instead of just the missing module.
I am trying to install a package named QSTK for a course that I am doing. The course points to an installation package for the 32 bit version, but I have 64 Python installed. I have found a .egg file listed on the Python packages index.
It seems to have an exe for 32 bit, but just the .egg for 64 bit. I downloaded the QSTK-0.2.6-py2.7.egg version and have been trying to install this unsucessfully so far.
Here is what I have tried:
Using easy install (from the C:\Python27\Lib\site-packages
directory):
Python easy_install -Z C:\Users\Prosserc\Downloads\QSTK-0.2.6-py2.7.egg
this has created a QSTK-0.2.6-py2.7.egg directory in my
site-packages directory which I can open and find files in. However,
I have tried to import QSTK from the python shell and get the usual
"No module named..." import error.
I looked for a setup.py file as I have used these to install
packages before, but could not find one.
I have also looked at this thread which gives details of
installing a .egg file without using easy install, but cannot figure
out what changes I would need to make to the script provided as this
is to install a specific package that I already have.
If anyone can help by explaining either how I can install this .egg file correctly or by providing a link to the QSTK modules for python 2.7 64 bit in another format this would be greatly appreciated.
I have managed to install the packages that QSTK is dependant on okay (numpy, scipy, matplotlib, pandas, python-dateutil and scikit-learn).
You should add -m before easy_install
for example:
python -m easy_install C:\Users\Prosserc\Downloads\QSTK-0.2.6-py2.7.egg
How about if you unpack the .egg (it's just a .zip in disguise), then cd into it and run python setup.py install? Will that run fine and will you then be able to import your module?
I'm saying this because if the .egg file does get put under site-packages as appropriate but you're still not able to import, this might be a problem in the code itself.
I have finally found another place to download this from with a package that works: https://pypi.python.org/pypi/QSTK/0.2.6 has a QSTK-0.2.6.tar.gz option to build it from the source code.
Unzipping this (then again once down to the .tar), I could find the setup.py file and install by going to the directory with the setup file and running:
python setup.py install
I tried copying the contents of the .egg folder in the path Lib\site-packages .
It worked and didn't throw any ModuleNotFoundError .
I found pip install qstk works perfectly for 64x 2.7 python at win 7
I just updated Python to 2.6.4 on my Mac.
I installed from the dmg package.
The binary did not seem to correctly set my Python path, so I added '/usr/local/lib/python2.6/site-packages' in .bash_profile
>>> pprint.pprint(sys.path)
['',
'/Users/Bryan/work/django-trunk',
'/usr/local/lib/python2.6/site-packages',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages']
Apparently that is not all the required paths because I can't run iPython.
$ ipython
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named `pkg_resources`
I've done Google searches and I can't really figure out how to install pkg_resources or make sure it's on the path.
What do I need to do to fix this?
I encountered the same ImportError. Somehow the setuptools package had been deleted in my Python environment.
To fix the issue, run the setup script for setuptools:
curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python
If you have any version of distribute, or any setuptools below 0.6, you will have to uninstall it first.*
See Installation Instructions for further details.
* If you already have a working distribute, upgrading it to the "compatibility wrapper" that switches you over to setuptools is easier. But if things are already broken, don't try that.
[UPDATE] TL;DR pkg_resources is provided by either Distribute or setuptools.
[UPDATE 2] As announced at PyCon 2013, the Distribute and setuptools projects have re-merged. Distribute is now deprecated and you should just use the new current setuptools. Try this:
curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python ez_setup.py
Or, better, use a current pip as the high level interface and which will use setuptools under the covers.
[Longer answer for OP's specific problem]:
You don't say in your question but I'm assuming you upgraded from the Apple-supplied Python (2.5 on 10.5 or 2.6.1 on 10.6) or that you upgraded from a python.org Python 2.5. In any of those cases, the important point is that each Python instance has its own library, including its own site-packages library, which is where additional packages are installed. (And none of them use /usr/local/lib by default, by the way.) That means you'll need to install those additional packages you need for your new python 2.6. The easiest way to do this is to first ensure that the new python2.6 appears first on your search $PATH (that is, typing python2.6 invokes it as expected); the python2.6 installer should have modified your .bash_profile to put its framework bin directory at the front of $PATH. Then install easy_install using setuptools following the instructions there. The pkg_resources module is also automatically installed by this step.
Then use the newly-installed version of easy_install (or pip) to install ipython.
easy_install ipython
or
pip install ipython
It should automatically get installed to the correct site-packages location for that python instance and you should be good to go.
In case of upgrading your python on mac os 10.7 and pkg_resources doesn't work, the simplest way to fix this is just reinstall setuptools as Ned mentioned above.
sudo pip install setuptools --upgrade
or sudo easy_install install setuptools --upgrade
On my system (OSX 10.6) that package is at
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
I hope that helps you figure out if it's missing or just not on your path.
The reason might be because the IPython module is not in your PYTHONPATH.
If you donwload IPython and then do
python setup.py install
The setup doesn't add the module IPython to your python path.
You might want to add it to your PYTHONPATH manually. It should work after you do :
export PYTHONPATH=/pathtoIPython:$PYTHONPATH
Add this line in your .bashrc or .profile to make it permanent.
I realize this is not related to OSX, but on an embedded system (Beagle Bone Angstrom) I had the exact same error message. Installing the following ipk packages solved it.
opkg install python-setuptools
opkg install python-pip
I got this error on Ubuntu, and the following worked for me:
Removed the dropbox binaries and download them again, by running:
sudo rm -rf /var/lib/dropbox/.dropbox-dist
dropbox start -i
I encountered with the same problem when i am working on autobahn related project.
1) So I download the setuptools.-0.9.8.tar.gz form https://pypi.python.org/packages/source/s/setuptools/ and extract it.
2 )Then i get the pkg_resources module and copy it to the folder where it needed.
**in my case that folder was C:\Python27\Lib\site-packages\autobahn
In my case, package python-pygments was missed. You can fix it by command:
sudo apt-get install python-pygments
If there is problem with pandoc. You should install pandoc and pandoc-citeproc.
sudo apt-get install pandoc pandoc-citeproc
Try this only if you are ok with uninstalling python.
I uninstalled python using
brew uninstall python
then later installed using
brew install python
then it worked!