Python: Sharing python site-packages libraries between two python installations - python

I have Python 2.7 installed on my C: drive. I then install Python 2.7 on a separate machine and copy the folder onto my J: drive. How can I share or point the J: installation of python to use my C: drive site-package packages?
i.e. How can I share my site-packages path between two installations of Python on the same machine?
When I try to install wxPython with pip and virtualenv I get the following:
pip install wxPython
Downloading from URLhttp://downloads.sourceforge.net/wxpython/wxPython-src-3.0.2.0.tar.bz2 (from http://wxPython.org/download.php)
Running setup.py egg_info for package wxPython
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '.virtualenvs\\engineer\\build\\wxPython\\setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: .virtualenvs\\engineer\\build\\wxPython\\setup.py
I find it difficult to build and compile on windows however the wxPython installer seems to work with virtualenv.
The comments below are useful however the question which I am asking is now that I have almost all of the packages in the virtualenv how can I make a reference to the packages which I do not have access to and are proprietary but can be installed by the user at a later date in their own python installation?
So far I have stumbled across the PkgResource api which maybe what I need.

The way to resolve this external dependency where the user does not have the power of including it in the virtualenv package is to use the package called pkg_resources:
Python code
# One approach is to find pythonhome by an environment variable
# Another is to use the windows registry but beware of different
# issue regarding 64 and 32 bit windows as shown in the link below:
Python _winreg woes
import pkg_resources
import os
pythonhome = os.environ["PYTHONHOME"]
pkgs = pkg_resources.find_distributions(pythonhome + "/Lib/site-packages")
for pkg in pkgs:
pkg_resources.working_set.add(pkg)
# import the modules
# Note: that this does not import the dependencies of the packages imported
# You could get the dependencies by following the guide here:
pkg_resource documentation
keeping in mind the following:
(Naive way of doing this:)
import pkg_resources
distributions, errors = pkg_resources.working_set.find_plugins(pkg_resources.Environment(("C:/Python27/Lib/site-packages",)))
for dsts in distributions:
for requirements in dsts.requires():
# load the requirements aswell
for requiredDsts in list(distributions):
if requirements.project_name == requiredDsts.project_name and requirements.version >= requiredDsts.specs[0][1]:
# the >= may not be whats required as it is specified in specs[0][0]
pkg_resources.working_set.add(requiredDsts)
To get setup with the virtualenv follow the instructions as given by the link provided by (bruno desthuilliers) https://pypi.python.org/pypi/virtualenv/12.0.5 followed by a nice tutorial for windows users windows tutorial on virtualenv (link provided by bruno desthuilliers):
Activate the current virtual environment
Download and install wxPython from the website (it will pickup the virtualenv)
Install any other dependencies via pip or easy_install
Perform the operation above with pkg_resources to include any packages which cannot be installed via pip or easy_install and that the user would have to install them manually.
Note: you can only import packages which are suitable for the python interpreter itself such as 32 bit or 64 bit

Related

ImportError in Python

I tried to execute a program using geonames_rdf, but I cant execute it by this error:
Traceback (most recent call last):
File "geo1.py", line 13, in <module>
import geonames.config.log
ImportError: No module named config.log
I read several posts abot ImportError and I check the path of the system and it is correct. I'm working in a VirtualBox with a fresh Ubuntu 16.04.
The imports of my program are:
import sys
import os
import os.path
import logging
import geonames.config.log
import geonames.compat
import geonames.adapters.search
I've also tried add this line:
sys.path.append('/usr/local/lib/python2.7/dist-packages/geonames/')
The command that I used to instal this package was
sudo pip install geonames_rdf
Try appending site-packages not dist-packages. A bit of searching it looks like dist-packages is debian specific.
sys.path.append('/usr/local/lib/python2.7/site-packages/geonames/')
Reason:
Since you're installing 3rd party python package via pip it will not go into dist-packages and python rightfully cannot find it on the path.
Reference link:
What's the difference between dist-packages and site-packages?
I just tried to use geonames_rdf, but I didn't know I needed it to do a geonames search so I installed geonames first, then discovered I had to install fiona and gdal (I'm on Windows, had to install these two using prebuilt whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/). Don't know why these dependencies aren't baked into geonames.
Anyway once I then installed geonames_rdf it seemed to install into the geonames folder in c:\Python27\lib\site-packages, added at least the adapters package. In c:\Python27\lib\site-packages\geonames there is a config folder with log.py in it.

Python 3 installing tweepy

I have looked at all the forums, but nothing has worked so far. I have spent hours trying to install it so any help would be appreciated.
i have downloaded and unzipped tweepy, went on to the command prompt, typed "cd tweepy-master". This works, but when i type "python setup.py install" or "python setup.py build".
When i type "python setup.py install" the error says.
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from setuptools import setup, find_packages
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
When i type "python setup.py build"
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from setuptools import setup, find_packages
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
I saw alot of people saying to use pip, but i am struggling to install that to.
Thanks for the help
pip is the good way to install a package. If you are not interested then you can install from source.
But you have to remember that, If you are using virtualenv or virtualenvwrapper then you can use python setup.py install otherwise you should use sudo python setup.py install.
If you are windows user then, open your cmd with administator privilege and type python setup.py install.
Have you installed Python using the Windows installer from python.org?
Cause this comes with pip already bundled into it. (I can not check the exact location atm, as I am on a Mac, but according to this SO post it should be located under C:\PythonX.X\Scripts, if you kept the default install location - otherwise it should be located in <path-to-python>\Scripts of course).
Otherwise pip can easily installed using this script. Simply call python get-pip.py in the script location and pip should be available afterwards (if not directly from commandline with pip, than at least by using python -m pip.)
Having pip finally available, you should be able to easily install tweepy calling pip install tweepy (or python -m pip install tweepy respectively).
For further information on pip and the other options to install it, check https://pip.pypa.io/en/stable/installing/.
PS. If installing the package via pip does not work, this may be a compatibility issue. According to the tweepy github-page python 3.2 is not amongst the supported python versions. So if your portable python really has an interpreter versioned 3.2.... (you can check the version of your interpreter running python from cmd, which should print something like > Python 3.X.X), the package may not run properly at all (even if you can install it without a problem).
As the portable python apparently is no longer supported anyways, it may be worth trying a different solution. There are plenty suggested on the portable python website (I just know about Anaconda, but this works flawlessly). But if you only want to use python with tweepy and don't need anything like scipy or numpy, I'd suggest simply downloading the installer from the official website. As said, pip gets shipped with the standard installation and can be used to easily install most of the packages you will need. (Except for e.g. the abovementioned scipy/numpy, which require additional non-python libraries whose "manual" installation may not be worth the trouble and hence legitimates the use of a more comprehensive environment like Anaconda).

Installing bsddb3 6.1.1 in Windows: FileNotFoundError: 'db/include\\db.h'

I'm running Windows 7 x64, with Python 3.4. When I run pip install bsddb3 I get:
λ pip install bsddb3
Collecting bsddb3
Using cached bsddb3-6.1.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "C:\Users\User\AppData\Local\Temp\pip-build-soqf0_qb\bsddb3\setup.py", line 42, in <module>
import setup3
File "C:\Users\User\AppData\Local\Temp\pip-build-soqf0_qb\bsddb3\setup3.py", line 375, in <module>
with open(os.path.join(incdir, 'db.h'), 'r') as f :
FileNotFoundError: [Errno 2] No such file or directory: 'db/include\\db.h'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\User\AppData\Local\Temp\pip-build-soqf0_qb\bsddb3
So I tried downloading the sources for bsddb3. I made sure I had the BSD DB Windows binaries from Oracle installed; I downloaded them from Berkeley DB 6.1.26.msi. Moving the include and lib directories from the DB install to a /db directory in the bsddb3 folder fixed the problem of not being able to find the libraries. But then the setup failed on a missing variable that's in the posix section but not properly declared in the Windows section.
Fixing that, and a couple of other adjustments, and python setup.py build actually ran the build, but after a bunch of warnings about unsafe conversions it failed with an error:
warning: I don't know what to do with 'runtime_library_dirs': ['db/lib']
error: don't know how to set runtime library search path for MSVC++
I'm not sure what to do next. Other than rewrite the library I was originally trying to use so that it uses SQLAlchemy instead or something.
One don't really want to spend couple of nights compiling that on Windows, so the best option is to use pre-built binary from Unofficial Windows Binaries for Python Extension Packages.
Download the package for your Python version (cpXX part of the name) and architecture (win_amd64 or win32), like bsddb3-6.1.1-cp34-none-win_amd64.whl, and install it with pip:
pip install bsddb3-6.1.1-cp34-none-win_amd64.whl
Based on cyberj0g's answer.
https://www.lfd.uci.edu/~gohlke/pythonlibs/#bsddb3
pip install bsddb3-6.1.1-cp34-none-win_amd64.whl
Note: the cp part is corresponding to the CPython version.
which means cp36 is for CPython 3.6.And divided into 32-bit and 64-bit versions for windows
bsddb3‑6.2.5‑cp36‑cp36m‑win32.whl
bsddb3‑6.2.5‑cp36‑cp36m‑win_amd64.whl

Installing eyed3 in windows

trying to install eyed3 under python 2.7.5
I have done a google search and have been following what I found to install eyed3. The instructions were as follows
extract the zip file to a temp folder (filename eyeD3-0.7.3.zip) I
did using a temp folder on my desktop.
In the eyeD3 folder (under src) rename the init.py.in to
setup.py. I did not find _init++.py.in in the eyed3 folder, but
init_.py was,so I assumed this latest version used that file.
In the main folder (I assume eyeD3-0.7.3) run python setup.py.in
install. setup.py.in didnot exist, but I ran it anyway and got the
expected file not found message, however, setup.py did exist so I
executed python setup.py install and got the following Traceback
Traceback (most recent call last): File "C:\Users\Me\Desktop\New
folder\eyeD3-0.7.3\setup.py", line 10, in <module>
paver.tasks.main() File "paver-minilib.zip\paver\tasks.py", line
883, in main File "paver-minilib.zip\paver\tasks.py", line 851,
in _launch_pavement File "pavement.py", line 28, in <module>
import setuptools ImportError: No module named setuptools
a cmd line search of the python 2.7.5 dir and sub-directories did not find setuptools.py, however I did find the following two files
setuptools_build_ext.py and setuptools_extension.py.
Do I need to rename one of these files or do you know what I am doing wrong or what the fix would be?
Thank you
Depending on where you got your Python from, it may not have come with setuptools. In particular, it does not come in the standard Windows installers from Python.org.
Some packages' setup.py scripts have special code that tries to download and install setuptools (or distribute) if it's missing, or that bundles in just enough of setuptools into the package itself. But not all of them do.
The answer is to install setuptools yourself.
While you're at it, you probably want to also install pip, and then you can just pip install . from within the directory, or pip install eyeD3-0.7.3.zip without unzipping, or even just pip install eyeD3 without even downloading. (Among other things, it will also download and install any dependencies that eyeD3 might need.)
In fact, the eyeD3 installation docs explicitly say "Stable releases of eyeD3 are best installed via pip…".

setuptools easyinstall mysql-python-1.2.3

I have read a bunch of threads on setuptools here.
A lot of people seem not to like it very much.
But I need to install MySQL-python-1.2.3. and when I do that I get this error:
MySQL-python-1.2.3 X$ python setup.py cleanTraceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools
So it seems I need setuptools and that it is assumed that it is installed.
On the setuptools python homepage it says:
Setuptools will install itself using the matching version of Python (e.g. python2.4), and will place the easy_install executable in the default location for installing Python scripts (as determined by the standard distutils configuration files, or by the Python installation).
Does this mean it will replace any default easy install from python?
If so I dont want to use it.
If so can I install MySQL-python-1.2.3 without setupttools?
Thanks
You should use virtualenv and pip.
Virtualenv automatically creates a setuptools version within the new environment, so the default one is intact.
You may want to read how the packaging and installing works: 1, 2

Categories

Resources