0

I'm wondering whether it is possible to use classes and methods contained within a library without:

  1. Importing the library through pip install
  2. Moving folders into site-packages
  3. Editing the system PATH

So far the answers I've seen on stack overflow use the methods listed above but my specific use-case requires that I don't pip install things and that the system PATH remains unchanged.

The specific library I'm interested in is Basemap

Is this possible and if so, how?

Arda Arslan
  • 1,331
  • 13
  • 24
  • Um, if your library provides a `setup.py`, you can install it this way. – ForceBru Jul 21 '17 at 15:10
  • 1
    I don't necessarily want to "install" the library. I want to be able to move my program from computer to computer to computer without having to worry about individually installing or tinkering with things. – Arda Arslan Jul 21 '17 at 15:15
  • You can't import modules without having installed them first, this no Go. – ForceBru Jul 21 '17 at 16:03

2 Answers2

0

Move your library to the site-packages folder (in your python install directory) and you should be able to import the modules normally from elsewhere, without having to change PATH.

Andrew Wang
  • 75
  • 1
  • 5
  • 1
    I should have included in my question that I can't add things to `site-packages`. I've updated the main post. – Arda Arslan Jul 21 '17 at 15:18
  • 1
    @ArdaArslan see [this question](https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path) – Andrew Wang Jul 21 '17 at 15:26
0

I was able to solve my problem by installing Basemap and pyproj on a separate computer using pip install. I then took those folders contained within Python\Python35\Lib\site-packages, copied them over to the computer I can't edit stuff on and into the folder containing my main script.

From there I can call stuff pretty much like normal, I just changed from mpl_toolkits.basemap import Basemap to from basemap import Basemap

Arda Arslan
  • 1,331
  • 13
  • 24
  • You will easily miss some of basemap's dependencies:- proj4, geos, and pillow. Moreover, the path to basic map data for plotting is out of place, causing unexpected behavior. – swatchai Jul 25 '17 at 07:01
  • I was able to move the required dependencies into a Resources folder and changed the calls from basemap's `__init__` script to call them from the appropriate paths. I recognize it's not an ideal solution but I have unideal problem, and the solution works. @swatchai – Arda Arslan Jul 25 '17 at 15:15