2

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.

Har
  • 3,727
  • 10
  • 41
  • 75
  • Why would you do that ? – bruno desthuilliers Feb 09 '15 at 12:07
  • I have my own libraries which are distributed in that J: python build and then there are the shared libraries which I do not own that are located in the C: python installation – Har Feb 09 '15 at 12:09
  • 3
    Then use virtualenv : https://pypi.python.org/pypi/virtualenv/12.0.5 - http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/ – bruno desthuilliers Feb 09 '15 at 12:12
  • This does not work when using wxPython as you cannot pip install it because it requires a compilation stage. – Har Feb 09 '15 at 12:27
  • PIL/Pillow, MySQLdb and quite a few other packages do require a compilation stage and they all work with `pip install`. – bruno desthuilliers Feb 09 '15 at 12:31
  • is there a way to make the virtualenv and wxPython installer work together nicely? I find it hard to compile on windows. Actually I am wrong it does work nicely with virtualenv :) Thanks for pointing that out. – Har Feb 09 '15 at 12:43

1 Answers1

1

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):

  1. Activate the current virtual environment

  2. Download and install wxPython from the website (it will pickup the virtualenv)

  3. Install any other dependencies via pip or easy_install

  4. 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

Community
  • 1
  • 1
Har
  • 3,727
  • 10
  • 41
  • 75