How to find Terminal
on MacOS?
Command + Space
and then type Terminal
How to get current Python version in Terminal?
python --version
How to install pyenv
on MacOS?
brew install pyenv
How to install necessary Python version in pyenv
?
pyenv install <necessary python version>
necessary python version
is something like that:3.8.0
,3.6.5
,2.7.3
, etc
How to install pyenv-virtualenv?
brew install pyenv-virtualenv
How to install virtualenv using pyenv
?
pyenv virtualenv <necessary python version> <virtualenv name>
necessary python version
is something like that:3.8.0
,3.6.5
,2.7.3
, etc
virtualenv name
is any string, something like that:test
,pet_project
,my_app
, etc.
if you get this error:
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly. Please restart current shell and try again.
you will need to add these two rows to .bashrc:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
How to do it?
- run this command in terminal:
sudo open ~/.bashrc
- Paste these two lines at the end of
.bashrc
file - Restart your terminal or reload
.bashrc
file by executing this commandsource ~/.bashrc
How to activate virtualenv using pyenv
?
pyenv activate <virtualenv name>
How to deactivate virtualenv using pyenv
?
pyenv adectivate
How to run Python interpreter?
python
How to close Python interpreter?
Control + D
How to run Python file from Terminal?
python <path to python file> (~/Desktop/hello.py)
Note: All Python files should have extension
py
.
- print(arg) - print value of
arg
variable in terminal
str
- string. Strings should be wrapped in single quote '
or in double quotes "
or in three single quotes '''
or in three double quotes """
Examples of str
:
'Hello World'
"Hello World"
'''Hello
World'''
"""Hello
World"""
It is possible to concatenate (add) strings
>>>print('Hello' + ' ' + 'World')
'Hello World'