Running external package in Python

A forum for general discussion of the Python programming language.

Running external package in Python

Postby gladaki » Tue Jan 14, 2014 8:27 pm

Hi All !
I am a beginner in python. I just installed a external packge in python 2.7 with setup.py. so when i type help(package1) i can see its help and installed
But i am not able to use the functions in that package..can some one help me with it. Following are my questions
1. This is how my directory look like packag1>A B C D _init.py
so my init.py looks like
Code: Select all
import A
import B
import C
import D

__all__=["A", "B", "C", "D"]


now when i go in directort A , I have three files
__init__.py reflection.py timedepthconv.py
relflection.py has many functions one of them is def oa(a,b,c,d,e)...and in __init__.py i can there is import oa with other functions..

Now my question
1.What is __init__.py file
2.How can i use function oa...
I tried using import Package1
oa(1,2,3,4,5) but it says oa is not defined...I already installed the package in python then why its not recognzing the function
thanks
Last edited by stranac on Tue Jan 14, 2014 8:30 pm, edited 1 time in total.
gladaki
 
Posts: 1
Joined: Tue Jan 14, 2014 8:16 pm

Re: Running external package in Python

Postby tnknepp » Tue Jan 14, 2014 9:10 pm

Do one of the following instead:

Code: Select all
import reflection
reflection.oa(a,b,c,d,e)

# OR
from reflection import * # usually not favored for some reason
oa(a,b,c,d,e)

Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
tnknepp
 
Posts: 133
Joined: Mon Mar 11, 2013 7:41 pm

Re: Running external package in Python

Postby ochichinyezaboombwa » Tue Jan 14, 2014 10:59 pm

You don't need to change your working directory in order for import to succeed.
a) if you install standard libraries the installation process takes care of everything; just "include your_module" should work from everywhere;
b) if you import your own libraries (modules), you need to have the env. variable PYTHONPATH set properly (read about it) and __init__.py in each of your directories.
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 2 guests