pip download -d /tmp/pip_wheels -r reqs.txt
- Download specified wheels in a directorypip freeze > reqs.txt
- Generate reqs.txt having all installed packages and their versionspip install "package>=0.2,<0.3"
- Install a specific version of pip packagepip install --no-cache-dir --find-links=/tmp/pip_wheels -r reqs.txt
- Install wheels from the locally directory before fetching it from PyPI repo + No cache the wheel.pip install --upgrade <pip-package-name>
- Upgrade a packagepip install -r reqs.txt
- Install package(s) specified in the reqs.txtpip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <pip-package-name>
- Install package by forcing that pip source is trustedpip list --outdated --format=freeze
- Show list of outdated installed packagespip list
- Show list of installed packagespip show <pip-package-name>
- Show info related a pip package
python -m site
- System wide python installation folderpython -m site --user-site
- Use specific python isntallation folderpython -c "import site; print(site.getsitepackages())"
- Get site package folders in python
python-config --prefix
- Python installation folderpython-config --exec-prefix
- Python installation folderpython-config --includes
- Show python includes folders with -Ipython-config --libs
- Show python librariespython-config --cflags
- Show CFLAGS used by Pythonpython-config --ldflags
- Show LDFLAGS used by Pythonpython-config --extension-suffix
- Show extension of python libspython-config --configdir
- Show config directory of python
- Create python venv
$ virtualenv -p /usr/bin/python2.7 my_project
$ source my_project/bin/activate
$ source my_project/bin/activate.fish (Using fish shell)
$ pip freeze > reqs.txt
$ dactivate
pip install --upgrade pip
- To upgrade pip; not recommended, I have always found pip broken afterwardspython -m pip install --upgrade pip
- Recommended command to upgrade pip.
- Single line for loop
- Compare two lists
- Get list of diff
- Convert list of lists to list
- Convert dictionary to tuple
- Convert dictionary to tuple by order
- Convert list of tuple to list
- Convert tuple to list
- Path manipulation
- Scan a folder
- Watch a folder
- Singleton class object
- Thread
- Read/Write JSON data
- Read/Write YAML data
- PyQt5 -- Hello world
- PyQt5 -- Dialog from UI file
- PyQt5 -- QThread
- Different errors faced during development
- Error
The directory '~/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '~/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- Solution
sudo -H pip3 install <package-name>
- Error
$ pip3 install numpy
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
Solution
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall