Python library issue - python

I have a very peculiar issue with Python library. I downloaded the a python library source, changed some code and used python setup.py install to install the library.
The original library was already installed with easy_install. Later on I further changed some source code and called the command python setup.py install again. When I use the library in code, I randomly get different versions of the library being called. I am not able to fully uninstall the library too, even though by both easy_install -m and pip both say uninstall successful, the library persists.
The environment is Ubuntu 11.04
Edit: When I call the same function from Python commandLine the latest build is called, but when I call python myfile.py which uses the library it calls an older build.

An installer typically loads a third-party library code in the site-packages directory. You can go to that directory and delete the library (that will include new and old versions). Then you can do a fresh install (using setup.py on your edited source).
If the library is somewhere else on the path, you can find it with:
>>> import somelib
>>> print somelib.__file__

Related

Does building pure python modules w/ conda require setuptools?

This weekend I've been reading up on conda and the python packaging user guide because I have a simple pure python project that depends on numpy. It seemed to me that distributing/installing this project via conda was better than pip due to this dependency.
One thing on which I'm still not clear: conda will install a python package from a recipe in build.sh, but it seems like build.sh just ends up calling python setup.py install for most python packages.
So even if I want to distribute/install my python package with conda, I still end up depending on setuptools (or distutils) for the actual installation, correct? I was unable to find a conda utility analogous to setuptools; am I missing something?
FWIW, I posted this question on the conda issue tracker.
Thanks!
Typically you will still be using distutils (or setuptools if the library requires it) to install things, yes. It is not technically required. The build.sh can be anything. If you wanted to, you could just copy the code into site-packages. Using setup.py install is recommended, though, as libraries will already have setup.py working, it will install metadata that can be read by pip, and it will compile any extension modules and install any data files.

ImportError: No module named requests - Python

I get an error message when I run the following line of code
import requests
Here is the error message
Traceback (most recent call last):
File "C:\Python27\test", line 1, in <module>
import requests
ImportError: No module named requests
Based on what I've seen from other posts, the common reason for the problem is individuals download the requests module but have not installed it. I downloaded the tarball, unzipped it and installed the setup.py file via the computer command line. There is a requests-2.4.0-py2.7.egg folder in the Python27/Lib/site-packages folder.
For Windows, install pip. You'll probably need other packages later on, so it will pay off to have a proper package manager.
Here is the documentation: https://pip.pypa.io/en/latest/index.html
You might actually be missing certifi module.
Overview:
From your error stack trace, it appears that you are using Windows platform and have the native windows Python installation. So I will stick to Windows instructions here. But since I have Cygwin based python installation, I will provide here cygwin-based steps to resolve your issue.
However, you can very easily use these steps on the Windows command prompt as well, by installing pip or easy_install, pre-built binary, or source code.
Windows-Cygwin-Pip way:
Add the directory that hosts python executable to your environment's PATH variable. Instructions here
Get pip to easily install new python packages. Best way is to download get-pip.py in cygwin’s home directory and run python get-pip.py in cygwin bash shell command prompt. Detailed and Alternative instructions here
Run pip install requests in the cygwin bash shell. It will install requests and certifi packages, which results in results, requests-2.4.0.dist-info, certifi, and certifi-14.05.14-py2.7.egg-info in the /lib/site-packages folder.
Run python and execute your original line of code import requests. It will run without errors.
Alternatives Ways to Installing a New Package:
There are several other alternatives of downloading this requests package, or for that matter any new python package. These include:
Getting easy_install in Cygwin and Running easy_install requests. Get easy_install in cygwin by installing setuptools package or by following instructions here.
Downloading a pre-built binary available here. And running it as executable. It will automatically install the module under the latest python installation available in windows registry.
Downloading source code for requests from Github into the home directory and Running python setup.py install
Python-Requests Installation Doc:
There is a brief list of ways to install requests available on the original python-requests project website as well. See here.
For a more productive environment and saving lots of headaches, follow these steps:
Install virtualenv
Install virtualenvwrapper
Always manage your environments with virtualenvwrapper
Always use pip to install dependencies inside your virtual environment
Use 'pip freeze --local' to see what's installed or to produce a requirements.txt file (pip freeze --local > requirements.txt )
If you have no idea what I'm talking about, you should spend some time reading up on these things, and you'll discover one of the many things that makes python so nice to work with (well, ok other programming languages have similar tools)

Can't install Python's IMAPClient

Trying to install IMAPClient using the command pip install IMAPClient. I'm on Windows, with Python 3.3.
It downloads fine, begins to install, then complains with ImportError: No module named 'response_parser'. I think that is an internal module for this library, so isn't something I can install separately.
I also tried to download the tarball manually, unpack it, and run python setup.py install, but get the same error.
This is a popular and stable library, so I realise I'm doing something wrong. I'm still a Python noob. What should I do?
From the home page:
Python versions 2.4 through 2.7 are currently supported. Python 3 support is in the works.
It would be nicer if they updated the setup file and/or the package metadata so it could immediately give you a clear error saying "Python 3 is not yet supported" or the like, instead of a mysterious failure from the middle of the setup process. But many projects don't bother to do that, preferring to put that energy into finishing the Python 3 port instead.
However, if you look at the source page:
Python versions 2.6, 2.7, 3.2, and 3.3 are officially supported.
So, it looks like the Python 3 support is actually done, but just hasn't been pushed to PyPI yet.
Which means that, if you have mercurial installed, you should be able to do this:
pip-3.3 install hg+https://bitbucket.org/mjs0/imapclient
If you don't have mercurial (and don't want to install it), download the zipfile from the source page, unzip it, and pip-3.3 install . or python3.3 setup.py install from inside the source tree.
If you plan on distributing Python 3 code that requires IMAPClient, you may want to scan the mailing list archives (or join the mailing list and ask) to find out when it will be updated on PyPI.

Python3.3 can't find libpython3.3m.so in linux (pip-3.3)

I'm using ubuntu 12.10 with default python3.2. However I downloaded python 3.3 as its much more polished. Of course, since then I have a nightmare with installing modules for 3.3, as python3 packages from synaptic install to 3.2 dir. So, I installed pip using python 3.3. Now I have pip-3.3 command, great. But, when I tried "sudo pip-3.3 install PySide" I quickly got an error: "error: Failed to locate the Python library /usr/lib/libpython3.3m.so". What's more, when I run "sudo pip install PySide" (command for 2.7), it builded and installed and runs flawlessy. Pyvenv and virtualenv both fail too. But I wan't to do it non-env way,just install pyside to global 3.3 lib dir.
So how can I install that PySide to python 3.3? I just can't get it to work... It looks like I will have to stick with default ubuntu python 3 version (this one runs great, everything works both from pip and synaptic), but I like to use newest python as it gets better and better with every release.
Btw, if that matters I also got following warning before that error:
"package init file 'PySide/init.py' not found (or not a regular file)" and
"package init file 'pysideuic/init.py' not found (or not a regular file)"
Edit: I installed full python3.3 from synaptic, including pythoh3.3-dev, debug, lib etc. Everything.
And that dynamic python 3.3 lib exist in /usr/lib/x86_64-linux-gnu/libpython3.3m.so, maybe just python3.3 package for ubuntu is poor and installs it in wrong direction/doesn't do any symlinks tricks?
Please try this answer installing from source (PySide). Download pyside sources and install from source, follow the instructions on the link.

SQLite Library - Python Portability

I am writing some code that is intended to operate with a pre-bundled version of Python included with a program.
The issue is that it doesn't as yet include the Sqlite3 library which is a requirement of my code. Currently I have a wrapped that calls a system installed version of python2.7 to use the import.
Is there any way I can manually include or package this library to go with the code to make it more portable? My concern is that I require this to operate on Windows systems but it is less likely that they will have python2.7 available. (2.7 is the minimum as this included an update to the library)
Yes in python you have setup tools. You can use requirements.txt file and use pip install -r requirements.txt to install dependency.
pip link
pysqlite is also maintained as an external project, looks like they've got downloads all the way back to Python 2.3

Categories

Resources