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

丶灬走出姿态 提交于 2019-11-30 22:46:23

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).

hope this can help:)

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
user225312
  • 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.

Extract the archive and execute:

python setup.py install

Here is details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!