pip / conda / import

Revisiting a few things that I have sort of glossed over in my Python journey.

  1. conda / pip
    • If the conda install somepackage fails, you can try pip install somepackage instead, which uses the PyPI instead of Anaconda. Many scientific Anaconda packages are easier to install than the corresponding PyPI packages because they are pre-compiled for your platform. However, many packages are available on PyPI but not on Anaconda.
    • conda is a package management tool for installing scientific and analytical computing packages, which may be written in Python or other programming languages. conda also creates a virtual environment, like python-virtualenv does. conda is the package manager of Anaconda. Anaconda is a free Python distribution provided by Continuum Analytics, which includes over 195 of the most popular Python packages for science, math, engineering and data analysis.pip is a general purpose Python package installer. In addition, python-pip and python3-pip are in the default Ubuntu repositories. In most cases you would choose pip instead of conda if you want to install a Python package management application. To create a Python virtual environment without installing conda, you can install python-virtualenv from the Ubuntu Software Center.pip and conda use different packaging formats so they do not operate interchangeably, but you can use both tools side by side.
  2. import
    • imports work by searching the directories listed in sys.path.
    • Here’s what it looks like on my system:
import sys
print '\n'.join(sys.path)</pre>

C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\okcupyd-1.0.0a3-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\invoke-0.11.1-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\coloredlogs-5.0-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\wrapt-1.10.6-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\simplejson-3.8.1-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\humanfriendly-1.42-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\python27.zip
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\DLLs
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\plat-win
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\lib-tk
C:\Users\agoswami\AppData\Local\Continuum\Anaconda
c:\users\agoswami\appdata\local\continuum\anaconda\lib\site-packages\sphinx-1.3.1-py2.7.egg
c:\users\agoswami\appdata\local\continuum\anaconda\lib\site-packages\setuptools-17.1.1-py2.7.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\cryptography-0.9.1-py2.7-win-amd64.egg
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\win32
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\win32\lib
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\Pythonwin
C:\Users\agoswami\AppData\Local\Continuum\Anaconda\lib\site-packages\IPython\extensions
C:\Users\agoswami\.ipython

So Python will find any packages that have been installed to those locations.

3. Pyspark.

When I was doing spark development, I wanted to use something like Spyder. This led me to dig into how topics like PYTHONPATH and stuff.

4.  Install / Update packages for specific versions of python.

 

Verify for Python2.7:


pd.__file__
Out[3]: '/home/abgoswam/.local/lib/python2.7/site-packages/pandas/__init__.pyc'

pd.__version__
Out[4]: u'0.19.1'

References:

  1. https://leifengtechblog.wordpress.com/category/programming-language/python/
  2. http://askubuntu.com/questions/574424/what-is-the-difference-between-pip-and-conda
  3. https://leemendelowitz.github.io/blog/how-does-python-find-packages.html
    • This is a useful one to understand packages
  4. https://python4astronomers.github.io/installation/packages.html
  5. https://azure.microsoft.com/en-us/documentation/articles/machine-learning-execute-python-scripts/
    • This is in fact another simple example of how import works  (look at the section ‘Importing existing Python script modules’)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s