All things Python
- Python in Windows
- Python in *nix: Mac (Unix) and Linux
- Nice Python packages and how and why I use them compared to others
- A
setup.cfg
template for my Python projects/ packages
All things Python
setup.cfg
template for my Python projects/ packagesUsage:
To skip file enter this comment in that file, preferably at the top.
# flake8: noqa
To not issue warnings, add the following comment at the end of the file.
# noqa
# or
# noqa: <error-token>
# or
# noqa: <error-token>, <error-token>...
VS Code
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Args": [
"--max-line-length=200",
"--ignore=D,E111,E127,E128,E225,E501,E731,E731,E901,F403,F405,W291,W293,W391"
],
import pysnooper
@pysnooper.snoop()
brew install pyenv
pyenv install <version>
. For the full list, run pyenv install --list
Always use virtual environments
Virtualenv
For a specific directory set python version: pyenv local <version>
mkvirtualenv --python=$(pyenv which python) <env name>
Then use workon
(that comes with virtualenv-wrapper)
Steps:
Add to Path
in the installation windows, otherwise:c:\Python36\
Python3 comes with pip installed.
Add to Path
Click on Add to Path
in the installation windows, otherwise:
Navigate to My Computer (System)/ Properties/ Advanced Settings/ Environment Variables and add c:\Python27\
(for Python2) and/or c:\Python36\
(for Python3)
Update shell command to call python
If you are one version of Python skip this part. Otherwise, I would advise to update the less used python version as described below:
For:
python2
python3
Python3 comes with pip installed.
Install pip in python2
python get-pip.py
or if you updated the shell command:
python2 get-pip.py
# https://https://gist.github.com/forkcs/76de0ea947a2fd27b131f9fa49bc1968 | |
[metadata] | |
name = {name} | |
version = {version} | |
author = Fedor Soldatkin | |
author-email = [email protected] | |
home-page = https://github.com/forkcs/{name} | |
description = {description} | |
long-description = file: README.md, CHANGELOG.md | |
long-description-content-type: text/markdown | |
license = APACHE 2.0 | |
license-file = LICENSE | |
platform = any | |
keywords = {keywords} | |
classifiers = | |
Development Status :: 3 - Alpha | |
Intended Audience :: Developers | |
License :: OSI Approved :: Apache 2.0 License | |
Operating System :: OS Independent | |
Programming Language :: Python | |
Programming Language :: Python :: 2.7 | |
Programming Language :: Python :: 3.3 | |
Programming Language :: Python :: 3.4 | |
Programming Language :: Python :: 3.5 | |
Programming Language :: Python :: 3.6 | |
Programming Language :: Python :: 3.7 | |
Programming Language :: Python :: 3.8 | |
Topic :: Software Development :: Libraries :: Python Modules | |
[options] | |
zip_safe = false | |
include_package_data = true | |
python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.* | |
packages = {name} | |
test_suite = tests | |
setup_requires = | |
setuptools | |
# setuptools >=30.3.0 # minimal version for `setup.cfg` | |
# setuptools >=38.3.0 # version with most `setup.cfg` bugfixes | |
install_requires = | |
{install_requires} | |
tests_require = | |
{tests_require} | |
[options.extras_require] | |
dev = | |
docutils | |
Pygments | |
test = | |
green | |
coverage | |
ci = | |
# codacy-coverage | |
# codecov | |
[bdist_wheel] | |
universal = true | |
[check] | |
metadata = true | |
restructuredtext = true | |
strict = true | |
[sdist] | |
formats = zip, gztar | |
[coverage:report] | |
show_missing = true | |
exclude_lines = | |
pragma: no cover | |
if False | |
# @abc.abstractmethod | |
# @abc.abstractproperty | |
# raise NotImplementedError | |
# return NotImplemented | |
# except ImportError | |
[green] | |
file-pattern = test_*.py | |
verbose = 2 | |
no-skip-report = true | |
quiet-stdout = true | |
run-coverage = true | |
[pydocstyle] | |
match-dir = (?!tests)(?!resources)(?!docs)[^\.].* | |
match = (?!test)(?!setup)[^\._].*\.py | |
inherit = false | |
ignore = D200, D203, D213, D406, D407 # Google conventions | |
[flake8] | |
max-line-length = 99 | |
doctests = True | |
exclude = .git, .eggs, __pycache__, tests/, docs/, build/, dist/ |
More details are here featuring the three main ways to create and use virtual environments in Python:
and bonus:
pipenv
# First install pipenv package:
<pip install pipenv>
cd project_folder
pipenv install <package>
pipenv run <script>
pipenv shell # Shell (Anthing run after this is done within the environment)
venv (Avaliable in python 3.3+)
python3 -m venv /path/to/new/virtual/environment
virtualenv
# First install virtualenv package:
<pip install virtualenv>
cd project_folder
# Create environment
virtualenv <environment-name>
# or
virtualenv </path/to/new/virtual/environment>
# Specify python version for the environment
virtualenv -p <python-version shell-command> <environment-name>
# or
virtualenv -p <python-version shell-command> </path/to/new/virtual/environment>
# Activate environment
source <environment-name>/bin/activate
# or
source </path/to/new/virtual/environment>/bin/activate
<pip install package>
deactivate
virtualenv-wrapper
# First install virtualenvwrapper package:
<pip install virtualenvwrapper>
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh
# or
source <path/to/virtualenvwrapper.sh>
mkvirtualenv <environment-name>
workon <environment-name>
deactivate
workon <previously-created-environment-name>
mkvirtualenv <previously-created-environment-name>
For Windows the package is virtualenvwrapper-win
and WORKON_HOME is %USERPROFILE%\Envs
by default.
Thank you, I had a bit of difficulty using VSC.
You're welcome.
Thank you, I had a bit of difficulty using VSC.