Created for
$ pip install --user pipenv
python -m site --user-base
# /home/username/.local
# add it to your ~/.profile or ~/.bashrc file, or:
export PATH=$PATH:/home/username/.local/bin
py -m site --user-site
#C:\Users\Username\AppData\Roaming\Python36\site-packages
# add to PATH:
C:\Users\Username\AppData\Roaming\Python36\Scripts
### Create virtualenv with system Python3:
$ pipenv --three
Creating a virtualenv for this project…
### Spawn a shell within the virtualenv
$ pipenv shell
Spawning environment shell...
### Exit the virtualenv
(course_intro-SmgljMaj) $ exit
exit
$
### Output virtualenv information
$ pipenv --venv
### Remove the virtualenv
$ pipenv --rm
Removing virtualenv...
All options available with: pipenv --help
PIPENV_VENV_IN_PROJECT=1
, pipenv will store the virtualenv in .venv/
folder per project bases and will name the virtualenv after your project name.
### install requests package and create a virenv, if there is no one
$ pipenv install requests
Installing requests…
### remove package
$ pipenv uninstall requests
Uninstalling requests-2.18.4
$ pipenv graph
my_ip.py
import requests
response = requests.get('https://httpbin.org/ip')
print('Your IP is {0}'.format(response.json()['origin']))
(course_intro-SmgljMaj) $ python my_ip.py
exit
Or type ctrl-d
Or close your terminal window :)
# install pyenv
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
# add it to path
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
#Create a new project using Python 3.6, specifically:
$ pipenv --python 3.6
# you'll be asked by pipenv if you want it to install the Python 3.6, if it is not inyour system
Intro to Pipenv - A Package Manager for Python by Pretty Printed
Install Python, PIP, Virtualenv, and Django on Windows 10 with PowerShell by CodingEntrepreneurs
We'll speak more on importing modules and managing dependencies in the theme "Organizing code: more on importing modules", but for now remeber just to use pipenv
instead of pip
whenever you want to play with some Python module/code.
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig("test.png")
plt.show()
example from: matplotlib.org
# navigate...
$ cd your/project/root/folder
# make sure you are in it - get your current working directory:
$ pwd
your/project/root/folder
try to run the simple_plot.py program
$ python simple_plot.py
Traceback (most recent call last):
File "simple_plot.py", line 1, in <module>
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot
Yes, an error occurs, because we do not have the required module (matplotlib) installed
We will install the required modules in a safe virtual environment by pipenv!
# install packages safely with pipenv:
$ pipenv install matplotlib
Creating a virtualenv for this project…
...
To activate this project`s virtualenv, run the following
$ pipenv shell
$ pipenv shel
Spawning environment shell...
# navigate to project folder
$ cd your/root/project/folder
# get into pipenv shell
$ pipenv shell
(my_project-hUoR8K1v) $
# get python path and copy it
(my_project-hUoR8K1v) $ which python
/home/nemsys/.local/share/virtualenvs/my_project-hUoR8K1v/bin/python
Preferences: Open Workspace Settings
python.pythonPath
in left panelYour workspace settings should look like:
{
"folders": [
{
"path": "."
}
],
"settings": {
"python.pythonPath": "/home/nemsys/.local/share/virtualenvs/my_project-hUoR8K1v/bin/python"
}
}
These slides are based on
customised version of
framework