Evgenii Legotckoi
Evgenii LegotckoiFeb. 18, 2018, 8:34 a.m.

Python 3 - Tutorial 002. Environment Setup

Python 3 is available for Windows, Mac OS and most versions of the Linux operating system.

Local Environment Setup

Open a terminal window and type "python" to find out if it is already installed and which version is installed.

Getting Python

Windows platform

Binaries of latest version of Python 3 (Python 3.6.4) are available on this download page

The following different installation options are available.

  • Windows x86-64 embeddable zip file
  • Windows x86-64 executable installer
  • Windows x86-64 web-based installer
  • Windows x86 embeddable zip file
  • Windows x86 executable installer
  • Windows x86 web-based installer

Note − In order to install Python 3.6.4, minimum OS requirements are Windows 7 with SP1. For versions 3.0 to 3.4.x Windows XP is acceptable.


Linux platform

Different flavors of Linux use different package managers for installation of new packages.

On Ubuntu Linux, Python 3 is installed using the following command from the terminal.

sudo apt-get install python3-minimal

Installation from source

Download Gzipped source tarball from Python's download URL - https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

Extract the tarball
tar xvfz Python-3.6.4.tgz
Configure and Install:
cd Python-3.6.4
./configure --prefix = /opt/python3.6.4
make  
sudo make install

Mac OS

Download Mac OS installers from this URL - https://www.python.org/downloads/mac-osx/

Double click this package file and follow the wizard instructions to install.

The most up-to-date and current source code, binaries, documentation, news, etc., is available on the official website of Python −

Python Official Website https://www.python.org/

You can download Python documentation from the following site. The documentation is available in HTML, PDF and PostScript formats.

Python Documentation Website www.python.org/doc/

Setting up PATH

Programs and other executable files can be in many directories. Hence, the operating systems provide a search path that lists the directories that it searches for executables.

The important features are −

  • The path is stored in an environment variable, which is a named string maintained by the operating system. This variable contains information available to the command shell and other programs
  • The path variable is named as PATH in Unix or Path in Windows (Unix is case-sensitive; Windows is not).
  • In Mac OS, the installer handles the path details. To invoke the Python interpreter from any particular directory, you must add the Python directory to your path.

Setting Path at Unix/Linux

To add the Python directory to the path for a particular session in Unix −

  • В csh shell - type setenv PATH "$ PATH:/usr/local/bin/python3" and press Enter.
  • В оболочке bash (Linux) - type PYTHONPATH=/usr/local/bin/python3.4 and press Enter.
  • В оболочке sh или ksh - type PATH = "$PATH:/usr/local/bin/python3" and press Enter.

Note . /usr/local/bin/python3 is the path of the Python directory.

Setting Path at Windows

To add the Python directory to the path for a particular session in Windows −

  • At the command prompt − type path %path%;C:\Python and press Enter.

Note − C:\Python is the path of the Python directory

Python Environment Variables

Here are important environment variables, which are recognized by Python −

S.No. Variable & Description
1 PYTHONPATH It has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer.
2 PYTHONSTARTUP It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH.
3 PYTHONCASEOK It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.
4 PYTHONHOME It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.

Running Python

There are three different ways to start Python −

Interactive Interpreter

You can start Python from Unix, DOS, or any other system that provides you a command-line interpreter or shell window.

Enter python the command line.

Start coding right away in the interactive interpreter.

$python             # Unix/Linux
or 
python%             # Unix/Linux
or 
C:>python           # Windows/DOS

Here is the list of all the available command line options −

S.No. Option & Description
1 -d provide debug output
2 -O generate optimized bytecode (resulting in .pyo files)
3 -S do not run import site to look for Python paths on startup
4 -v verbose output (detailed trace on import statements)
5 -X disable class-based built-in exceptions (just use strings); obsolete starting with version 1.6
6 -c cmd run Python script sent in as cmd string
7 file run Python script from given file

Script from the Command-line

A Python script can be executed at the command line by invoking the interpreter on your application, as shown in the following example.

$python  script.py          # Unix/Linux
or 
python% script.py           # Unix/Linux
or 
C:>python script.py         # Windows/DOS

Note − Be sure the file permission mode allows execution.

Integrated Development Environment

You can run Python from a Graphical User Interface (GUI) environment as well, if you have a GUI application on your system that supports Python.

For the development of Python applications, I recommend PyCharm from JetBrains, as the most developed and user-friendly IDE.

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
e
  • ehot
  • April 1, 2024, 2:29 a.m.

C++ - Тест 003. Условия и циклы

  • Result:78points,
  • Rating points2
B

C++ - Test 002. Constants

  • Result:16points,
  • Rating points-10
B

C++ - Test 001. The first program and data types

  • Result:46points,
  • Rating points-6
Last comments
k
kmssrFeb. 9, 2024, 7:43 a.m.
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVADec. 25, 2023, 11:30 p.m.
Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
J
JonnyJoDec. 25, 2023, 9:38 p.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
G
GvozdikDec. 19, 2023, 10:01 a.m.
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
a
a_vlasovApril 14, 2024, 6:41 p.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел Дорофеев
Павел ДорофеевApril 14, 2024, 2:35 p.m.
QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
f
fastrexApril 4, 2024, 4:47 p.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…
AC
Alexandru CodreanuJan. 20, 2024, 12:57 a.m.
QML Обнулить значения SpinBox Доброго времени суток, не могу разобраться с обнулением значение SpinBox находящего в делегате. import QtQuickimport QtQuick.ControlsWindow { width: 640 height: 480 visible: tr…

Follow us in social networks