Skip to content

Instantly share code, notes, and snippets.

@pavan538
Last active July 30, 2018 05:07
Python installation and packages
setup tools:
when ever there isa source distribution which consists of setup.py file, we can directly install using the following command
# cd foo.1.0/
# python setup.py install
if we need to split the build we can use the following commands
# python setup.py build
# python setup.py install
prefix, exec-prefix stands for the directories that Python is installed to, and where it finds its libraries at run-time.
By default when we install package in unix/mac using setup tools it will go to prefix/lib/pythonX.Y/site-packages
Alternate installations:
--user, or --home, or --prefix and --exec-prefix, or --install-base and --install-platbase
we can also install in other network file system as follows:
/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
# custom installation:
Python modules --install-purelib
extension modules --install-platlib
all modules --install-lib
scripts --install-scripts
data --install-data
C headers --install-headers
ex:
python setup.py install --home=~/python \
--install-purelib=lib \
--install-platlib='lib.$PLAT' \
--install-scripts=scripts
--install-data=data
# Difference between sdist and bdist :
setup.py sdist creates a source distribution: it contains setup.py, the source files of your module/script (.py files or .c/.cpp for binary modules), your data files, etc. The result is an archive that can then be used to recompile everything on any platform.
setup.py bdist (and bdist_*) creates a built distribution: it includes .pyc files, .so/.dll/.dylib for binary modules, .exe if using py2exe on Windows, your data files... but no setup.py. The result is an archive that is specific to a platform (for example linux-x86_64) and to a version of Python, and that can be installed simply by extracting it into the root of your filesystem (executables are in /usr/bin (or equivalent), data files in /usr/share, modules in /usr/lib/pythonX.X/site-packages/...). You can even build rpm archives that can be directly installed using your package manager.
Creating a Source Distribution:
# python setup.py sdist
# python setup.py sdist --formats=gztar,zip
We can specify, what are the extra files need to include in source distribution using MANIFEST file - MANIFEST.in
include *.txt
recursive-include examples *.txt *.py
prune examples/sample?/build
Setup tools:
let say we have a project and below are the following files in that project dir. we need to create a package for the following project.
setup.py
src/
mypkg/
__init__.py
module.py
data/
tables.dat
spoons.dat
forks.dat
In setup.py file:
setup(...,
packages=['mypkg'],
package_dir={'mypkg': 'src/mypkg'},
package_data={'mypkg': ['data/*.dat']},
)
Installing additional files:
setup(...,
data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('config', ['cfg/data.cfg']),
('/etc/init.d', ['init-script'])]
)
# Upload to the local repository
python setup.py sdist upload -r http://example.com/pypi
################################### PIP ##########################################################
# pip.conf example
[global]
index-url = http://download.zope.org/simple
trusted-host = download.zope.org
pypi.python.org
secondary.extra.host
extra-index-url= http://pypi.python.org/simple
http://secondary.extra.host/simple
##################################################################################################
How to install package from conda:
# conda install pip
# conda install docker-compose
# conda install virtualenv
- if you dont find any package from conda you can search as following
- # anaconda search -t conda json2xml
- And then you can install has following
- conda install -c auto json2xml
- conda install -c anaconda beautifulsoup4
How to Remove Ananconda: 7153
# conda install anaconda-clean
# anaconda-clean --yes
# rm -rf ~/anaconda3/
# rm -rf ~/.condarc ~/.conda ~/.continuum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment