How to refresh Eclipse if you add a new module to python ?

A forum for general discussion of the Python programming language.

How to refresh Eclipse if you add a new module to python ?

Postby hoboy » Sun Mar 17, 2013 11:40 am

I am new to python.
I have installed scitools-0.9.0.tar.gz from http://code.google.com/p/scitools/.
my question is how can I use it in a python project that I have created in eclipse ?
if it is java I will just add the jar file to my project classpath.
For example.
this is an example from scitools-0.9.0.tar.gz
-----------------------------------------------------------------------
"""Plot three curves. Use Matlab-style syntax."""
from scitools.std import *

# plot two curves in the same plot:
t = linspace(0, 3, 51) # 51 points between 0 and 3
y1 = t**2*exp(-t**2)
y2 = t**4*exp(-t**2)
# pick out each 4 points and add random noise:
t3 = t[::4]
random.seed(11)
y3 = y2[::4] + random.normal(loc=0, scale=0.02, size=len(t3))

# use Matlab syntax:
plot(t, y1, 'r-')
hold('on')
plot(t, y2, 'b-')
plot(t3, y3, 'bo')
legend('t^2*exp(-t^2)', 't^4*exp(-t^2)', 'data')
title('Simple Plot Demo')
axis([0, 3, -0.05, 0.6])
xlabel('t')
ylabel('y')
savefig('tmp0.eps') # this one can be included in latex
savefig('tmp0.png') # this one can be included in HTML
show()

raw_input('Press Return key to quit: ')
-----------------------------------------------------------------
When I create pydev project
add a file then past this one inside that file I get error in eclipse that show that
plot(t, y1, 'r-')
hold('on')
plot(t, y2, 'b-')
plot(t3, y3, 'bo')
legend('t^2*exp(-t^2)', 't^4*exp(-t^2)', 'data')
title('Simple Plot Demo')
axis([0, 3, -0.05, 0.6])
xlabel('t')
ylabel('y')
savefig('tmp0.eps') # this one can be included in latex
savefig('tmp0.png') # this one can be included in HTML
show()
Are not visible in eclipse, if it is java that tells me that these are not in my classpath.
I am new to python.
sorry for the newbie question
Last edited by Yoriz on Mon Mar 18, 2013 1:26 pm, edited 1 time in total.
Reason: Renamed the title
hoboy
 
Posts: 7
Joined: Sat Mar 16, 2013 5:33 pm

Re: How to use 3rd part python library in Eclipse ?

Postby setrofim » Sun Mar 17, 2013 12:39 pm

Basically,
  1. Extract the contents of the tar.gz file.
  2. Navigate into the extracted directory in your shell
  3. Run
    Code: Select all
    python setup.py install

    in that directory.
Python looks for modules in locations specified by sys.path variable. This variable is initialized with several locations when the interpreter start (notably, with the contents of PYTHONPATH--which is sort of like Java's classpath--environment variable, if it is set), and may be modified at run time (though this is generally discouraged). See documentation for more details.

In order to use a Python module you basically have two options: either place the module into one of the locations in sys.path, or add the location of the module to sys.path. The former options is generally best, and this is what setup.py that comes with most libraries does (among other things).

Please also note that the preferred way of installing packages in Python is to use pip rather than downloading the compressed source. With pip, all you need to do is run
Code: Select all
pip install scitools

in your shell (in any location you have write access to), and pip will download and install the latest version of the package for you.

I don't use Eclipse, so don't know if there is support for this in the IDE, but I wouldn't be surprised if pydev offered some kind of pip integration.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: How to use 3rd part python library in Eclipse ?

Postby hoboy » Sun Mar 17, 2013 3:07 pm

setrofim wrote:Basically,
  1. Extract the contents of the tar.gz file.
  2. Navigate into the extracted directory in your shell
  3. Run
    Code: Select all
    python setup.py install

    in that directory.
Python looks for modules in locations specified by sys.path variable. This variable is initialized with several locations when the interpreter start (notably, with the contents of PYTHONPATH--which is sort of like Java's classpath--environment variable, if it is set), and may be modified at run time (though this is generally discouraged). See documentation for more details.

In order to use a Python module you basically have two options: either place the module into one of the locations in sys.path, or add the location of the module to sys.path. The former options is generally best, and this is what setup.py that comes with most libraries does (among other things).

Please also note that the preferred way of installing packages in Python is to use pip rather than downloading the compressed source. With pip, all you need to do is run
Code: Select all
pip install scitools

in your shell (in any location you have write access to), and pip will download and install the latest version of the package for you.

I don't use Eclipse, so don't know if there is support for this in the IDE, but I wouldn't be surprised if pydev offered some kind of pip integration.


setrofim »
What IDE do you use for python developement ?
hoboy
 
Posts: 7
Joined: Sat Mar 16, 2013 5:33 pm

Re: How to use 3rd part python library in Eclipse ?

Postby hoboy » Sun Mar 17, 2013 3:08 pm

setrofim »
What IDE do you use for python developement ?
or what EDI python developers recommand
hoboy
 
Posts: 7
Joined: Sat Mar 16, 2013 5:33 pm

Re: How to use 3rd part python library in Eclipse ?

Postby setrofim » Sun Mar 17, 2013 3:44 pm

I use Vim. You don't really need an IDE when writing Python, and a lot of the Python developers just use a decent programmer's text editor with a few plugins. In my opinion, IDEs just get in the way when writing Python code. They tend to be too prescriptive in how the environment should be set up. Also, since Python is typically distributed and run from source, you're better off developing in a similar environment to the one the script will be running in in production (i.e. the system shell). Just my two cents; I know that others on this forum would disagree.

If you do want to use an IDE, my understanding is that Eclipse+PyDev is a reasonable choice; if you're already comfortable with Eclipse form Java development, that might be the way to go. There are also a few Python-specific IDEs around, but it's been literally years since I've looked into it in detail, so can't recommend anything specific.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: How to use 3rd part python library in Eclipse ?

Postby ichabod801 » Sun Mar 17, 2013 8:23 pm

I agree with setrofim (except I use UltraEdit, not vim). I do it because I work in Python, SAS, xml, html, and javascript. UltraEdit can handle all of them (as can vim, Notepadd++, or any other serious text editor). So I just have to learn one interface and I can use it for all of my projects, at home and at work.
Craig "Ichabod" O'Brien
Minimalist, buddhist, theist, and programmer
Current languages: Python, SAS, and C++
Previous serious languages: R, Java, VBA, Lisp, HyperTalk, BASIC
ichabod801
 
Posts: 84
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: How to use 3rd part python library in Eclipse ?

Postby metulburr » Sun Mar 17, 2013 8:54 pm

I bounce between Vim and Geany. I use Vim when on servers writing code, and Geany when i want a GUI
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1363
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: How to use 3rd part python library in Eclipse ?

Postby Yoriz » Mon Mar 18, 2013 1:10 pm

If you install a new module to python, do the following in eclipse to refresh the list of known modules.
  1. Mainmenu>Window>preferences.
  2. In the treeview on the left navigate to pydev> Interpreter - Python
  3. Click the remove button which is under auto config button.
  4. Click auto config button.
  5. Selection needed window will pop up, just click ok button.
  6. Click apply button.
  7. Click ok.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 759
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Discussions

Who is online

Users browsing this forum: metulburr and 2 guests