Introduction
Software creeping slowly into every day devices and everybody carrying around a device that easily outperforms a couple of 90s supercomputers is a clear indicator for the increased presence of software. The Number of projects hosted on a well known „developer-platform“ also indicates that the amount of software has increaseda lot in the last years. Long story made short: As a software developer there is no need to re-invent the wheel every now and then. Normally there is a library available for one or the other task that one has to solve. Question is how to pull foreign projects into your own python project? There is a couple of options!
pip
pip allows for installation of packages from the python package index which is an extensive repository of python packages. I cannot say what pip stands for
, but it is an extremly usefull tool. Using opensuse I had to install it first. The package is called python3-pip for me. Then I can start pulling in packages: Let’s say for some reason I would have to parse some java source codes from a python script. Since I am not willing to spend time on writing a Java Parse now I have a look at pypi and find this. I want to give it a try and pull in the package using pip:
$ pip install javalang
However since pip tries to install the package below /usr/lib/ the installation initially fails since I am not root… So I try again this time looking up in the pip manual that there is an option for installation into my home directory:
$ pip install --user javalang
and this time it works! Now I can start trying out the example code from the javalang github page
#!/usr/bin/python3
import javalang
tree = javalang.parse.parse("package javalang.brewtab.com; class Test {}")
print(tree)
$ ./javalang-test.py3
CompulationUnit
Which looks like the process of downloading the package and making it available to the python interpreter has worked as expected! Looking up information about the installed package reveals following information:
$ pip show javalang --- Metadata-Version: 1.1 Name: javalang Version: 0.10.1 Summary: Pure Python Java parser and tools Home-page: http://github.com/c2nes/javalang Author: Chris Thunes Author-email: cthunes@brewtab.com License: UNKNOWN Location: /home/user/pythonbase/lib/python3.4/site-packages Requires: six
Neueste Kommentare