jsommers / pytricia

A library for fast IP address lookup in Python.
GNU Lesser General Public License v3.0
214 stars 22 forks source link

ImportError: No module named pytricia -> setting PYTHONPATH is required #12

Closed dirkvdplas closed 7 years ago

dirkvdplas commented 7 years ago

I really like pytricia. But I do have a question When calling pytricia from a python script I get an importerror. Importing pytrica from interactive shell goes fine. Also running the script prepended with "python" goes fine. I figured out I have to manually set PYTHONPATH to directory where pytricia is installed (/usr/local/lib/python2.7/site-packages/)

Any idea what's going wrong? (I am using 0.9.4 version, installed via pip)

Below the first few lines of the script:

shell$ cat lookup-prefix.py

!/usr/bin/python

import pytricia import textfsm

route_table = pytricia.PyTricia()

+++++++++++++++++++++++ Running the script throws an error:

shell$ ./lookup-prefix.py Traceback (most recent call last): File "./lookup-prefix.py", line 3, in import pytricia ImportError: No module named pytricia

++++++++++++++++++++++++++++++++++ Importing pytricia via interactive shell goes fine:

shell$ python Python 2.7.12 (default, Nov 24 2016, 23:19:15) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import pytricia help(pytricia)

++++++++++++++++++++++++++++++++ Running the script with adding "python" upfront goes fine as well:

shell$ python lookup-prefix.py Please enter prefix to lookup:

++++++++++++++++++++++++++++++++++ It works fine when manually specifying PYTHONPATH:

shell$ export PYTHONPATH=/usr/local/lib/python2.7/site-packages/ shell$ echo $PYTHONPATH /usr/local/lib/python2.7/site-packages/ shell$ ./lookup-prefix.py Please enter prefix to lookup:

jsommers commented 7 years ago

I'd suspect that the python executable you're using is somehow not configured to look in the library folder where pytricia is installed. If you start python up with -v you'll see all the library paths that it loads on startup.

jsommers commented 7 years ago

@dirkvdplas Any response? If not, I'm going to close this.