![]() Additionally, the default list of packages available via conda are curated and maintained by Continuum Analytics, the creators of Anaconda. Thus it will attempt to install, upgrade, and downgrade packages as needed to accommodate your installations. First and foremost, conda has a powerful “environment solver”, which tracks the inter-dependencies of Python packages. There are substantial benefits for using conda rather than pip to install packages. In lieu of printing out your PYTHONPATH, you can look up the location of your site-packages directly:īoth managers will install packages to your site-packages directory. We can import NumPy wherever we’d like because it was placed in site-packages when it was installed, and the Python interpreter will always look in site-packages when attempting to fulfill an import statement. Site-packages is the target directory in which all installed Python packages are placed by default. Now note the last directory in PYTHONPATH: site-packages. This is why we took care to create our modules and packages in the same directory as our active Python session. If it does not find any package or module that satisfies the import statement, then it will proceed to check the next entry in PYTHONPATH. ![]() Note that the first entry in PYTHONPATH is '', meaning that the Python interpreter will first look in the current directory when trying to do an import. # looking up `PYTHONPATH` > import sys > sys. The official Python tutorial provides a nice overview of this material and dives into details that we will not concern ourselves with here. A brief overview will be provided of the two most popular venues for hosting Python packages to the world at large: the Python Package Index (PyPI) and. To conclude this section, we will demonstrate the process of installing a Python package on your system supposing that you have written your own Python package, installing it enables you to import it anywhere on your system. The standard library and other collections of Python code, but it will permit us to create our own packages of code. Detailing this packaging system will not only provide us with insight into the organization of py files from which we can import functions and objects, and packages are collections of such modules. ![]() Here, we will finally pay our due diligence and discuss Python’s import system, which entails understanding the way that code can be organized into modules and packages. # accessing `defaultdict` from the standard library's `collections` package from collections import defaultdict # import the entire numpy package, giving it the alias 'np' import numpy as npĭespite our regular use of the import statement, we have thus far swept its details under the rug.
0 Comments
Leave a Reply. |