juan
juan

Reputation: 81902

How can I use third party 'libraries' in python?

Disclaimer: This is a very basic question, but keep in mind I come from a Microsoft background, and I've programmed mostly in .NET with Visual Studio (this may help you help me with analogies perhaps)


I started programming a little python for the fun of it, so I downloaded eclipse, and installed PyDev.

I reached a point where I needed to parse a date, and I found an alternive to time.strptime that seemed interesting. That alternative was python-dateutil.

I went ahead and downloaded it, but I had problems when I tried to use it.
Apparently the download includes source files, and I had absolutely no idea how to use it in my "project" in eclipse.

So my very basic questions:

Thank you for your patience.

Upvotes: 5

Views: 17605

Answers (5)

Rajendra meena
Rajendra meena

Reputation: 21

The tarball you downloaded had a Makefile in it, so just use that:

make install Then, in the file where you want to use something from the new module, import it like any other Python module:

import dateutil

Upvotes: 1

user225312
user225312

Reputation: 131687

  • Do I need to include the source files directly with my files? Perhaps in a subdirectory? How would I use it in my code (how do I import them in my .py file)?

You just need to import the py file. For example, if your module is called x, you need to do a import x

  • Do I need to "build" (make?) them and reference them? How? How do you "compile" something like that in windows?

No. Just do an import x and a x.pyc file will be created. This is the byte-compiled version of the module x.

  • Am I totally missing some important point? Download the python-dateutil and extract it to a directory.

Then you need to do a (might require appropriate permissions on Windows. Read more here)

python setup.py install

This will automatically install (and thus copy) all the module files to a path where the Python interpreter can find them. You can find that by using: import sys and then print sys.path. These will be the locations where the interpreter will search for the modules.

After installation, start your interpreter and then try import dateutil. If all is well, the module should be imported.

When you need to distribute your application, all the necessary modules will be need to be packaged along. Note that you just need to include the py files and not pyc.

For a better understanding of packaging the source files, you need to read about the disutitls module. Here is the link.

Upvotes: 1

mouad
mouad

Reputation: 70031

I went ahead and downloaded it, but I had problems when I tried to use it. Apparently the download includes source files, and I had absolutely no idea how to use it in my "project" in eclipse.

you should use pip in your line of command type :

pip install python-dateutil

this command will do all the thing for you it will download and install the library automatically. if you don't have pip refer to the documentation above to see how you should install it

Do I need to include the source files directly with my files? Perhaps in a subdirectory? How would I use it in my code (how do I import them in my .py file)?

if you have used pip like above no need , you should now just import dateutil in your scripts to use it:

import dateutil

Do I need to "build" (make?) them and reference them? How? How do you "compile" something like that in windows?

everything is done with pip (magic isn't it :) )

Am I totally missing some important point?

Yes python is cool, easy and fun , forget about make ,make install ... Everything in python is easy installable.

And for the love of G.. please use pip (it's an order from the BDFL).

alt text

hope this can help:)

Upvotes: 11

ceth
ceth

Reputation: 45295

Extract the archive and execute:

python setup.py install

Here is details.

Upvotes: 0

nmichaels
nmichaels

Reputation: 50971

The tarball you downloaded had a Makefile in it, so just use that:

make install

Then, in the file where you want to use something from the new module, import it like any other Python module:

import dateutil

Upvotes: 1

Related Questions