Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python module not working (not able to import) even after including it in PATH variable

Tags:

python

I have one testing module that I want to use for android testing. I have the files but there is no installation file for it, so I added the module to PATH variable, even then it doesn't work I try to import it.

Any way to make it work. Do I have to paste them in Python folder only (and what it the Python file location). In windows, I use to paste all the files in Python folder and everything works perfectly fine. Here in Ubuntu I'm not able to find the location so I added it in PATH.

Any way out! Any help is appreciated.

Cheers

Some details: Python version: 2.7.2, Ubuntu 11.10 OS, Python module is in file/folder format with no "setup.py" file to install, Location of module already in PATH variable, Everything else in Python is working beside that module, same worked in Windows XP with Python 2.7.2 after copy pasting.

like image 600
MCan Avatar asked Feb 04 '12 19:02

MCan


2 Answers

PATH is for executables, PYTHONPATH is for Python modules.

You can also start your script with:

import sys
sys.path.append('/path/to/directory')
import your_module

Where /path/to/directory/your_module.py is the file you're importing.

The normal location for Python modules is in /usr/lib/pythonX.X/site-packages. For installing stuff as a user virtualenv is great.

like image 149
Rob Wouters Avatar answered Oct 24 '22 08:10

Rob Wouters


You can add a __init__.py file without any content to the directory which yo want to import.

The init.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string , from unintentionally hiding valid modules that occur later (deeper) on the module search path.

like image 22
Sandeep Chandel Avatar answered Oct 24 '22 07:10

Sandeep Chandel