Как установить Python
Чтобы запустить скрипт на Python, вам нужен интерпретатор Python. Pip понадобится, чтобы ставить библиотеки других разработчиков. Это 2 вещи, которые просто необходимы, чтобы начать программировать на своём компьютере.
Оказывается, первая установка этих программ бывает очень болезненной. Здесь собраны советы и ссылки, которые облегчат вам жизнь.
Мой компьютер думает, что у него уже есть Питон
На Linux или Mac может быть предустановлен Python 2. Это тоже Python, но он отличается от Python 3. Например, вместо print(«hello!») там используют print «hello!» . Короче, это не то, что нужно. Команды python и pip в таком случае будут запускать код и устанавливать пакеты для Python 2, используйте для Python 3 команды python3 и pip3 .
Как ставить Питон без терминала
Как ставить Питон в терминале
Если по какой-то причине способ со слайдов не подходит, вот гайды как ставить Python из терминала (на английском):
Как проверить, что получилось
Откройте терминал и напишите python —version , на экране появится версия установленного Python. Вам нужен третий Python, т.е. первой цифрой версии должна быть 3. Команда pip —version выведет версию pip . Используйте в командах python3 и pip3 вместо python и pip , если помимо третьего Питона у вас установлен ещё и второй.
Если вам кажется, что Python установился, но не запускается в терминале – он не добавился в параметр окружения PATH . Удалите Python и установите ещё раз, поставив галочку с этого слайда.
Попробуйте бесплатные уроки по Python
Получите крутое код-ревью от практикующих программистов с разбором ошибок и рекомендациями, на что обратить внимание — бесплатно.
Переходите на страницу учебных модулей «Девмана» и выбирайте тему.
Setting up Windows for Python¶
There are a number of python distributions available – many designed for easier support of scientific programming:
- Anaconda
- Enthought Canopy
- Python(x,y)
But for core use, the installer from python.org is the way to go, and that is what we will be using in this program.
You want the installer for Python 3.5.2 – probably 64 bit, though if you have a 32 bit sytem, you can get that. There is essentially no difference for the purposes of this course.
Double click and install.
Terminal¶
If you are confident in your use of the “DOS Box” or “powershell”, command lines, feel free to use one of those. However, your life may be easier if you install “Git Bash”, as then you can follow unix-style terminal instructions exactly, and do not have to translate. Also, your instructors are more experienced with Bash.
From now on, if you hear the terms ‘bash’, ‘shell’ or ‘terminal’, know that this is the application that is being referred to.
When you install Git Bash, you are installing git (and a git gui) as well, thus killing two birds with one stone, metaphorically speaking.
This is actually your best bet for running Python also – If you use the Git Bash shell, you can use the same commands as Linux and OS-X users. Regardless of which shell you choose, you will need to add Python to your environment. It is possible that this was done during the installation of python. If you type ‘which python’ into your terminal, and get back the answer ‘/c/python34/python’, then you are good to go, otherwise, follow the instructions here:
You will want to add:
git¶
If you installed Git Bash, you will already have git, both usable in the terminal and as a gui, and can safely skip this section. If not, you still need a git client. You can use the above link and install git (it will install the bash shell as well, of course, but you can use your shell of choice instead).
There is also TortoiseGit:
which integrates git with the file manager. Feel free to use this if you already have an understanding of how git works, but for the purposes of learning, it may be better to use a command line client (git Bash above).
pip¶
pip is the Python package installer. It is updated faster than python itself, so once you have python you want to get the latest version of pip working:
$ python -m ensurepip --upgrade
It should download and install the latest pip .
You can now use pip to install other packages.
Using pip:¶
To use pip to install a package, you invoke it with this command:
python -m pip install the_name_of_the_package
Where python is the command you use to invoke the python you want to use (could be python3 )
NOTE: You will frequently see advice to use pip like so:
$ pip install something_or_other
Which often works, but also can invoke the wrong version of pip. The above command:
$ python -m pip install something_or_other
calls python, and tells it to run the pip module. It is exactly the same as calling pip directly, except that you are assured that you are getting the version of pip connected the version of python that you are running.
iPython¶
One extra package we are going to use in class is iPython :
$ python -m pip install ipython[all]
You should now be able to run iPython from the git bash shell:
$ ipython Python 3.5.2 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35) Type "copyright", "credits" or "license" for more information. IPython 2.0.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details.
(or from the DOS box or PowerShell prompt)
We will use this as our default python interpreter.
© Copyright 2014, Christopher Barker, Cris Ewing, Maria McKinley.
HOW TO: Install and Use Python in Git Bash for Windows 10?
![]()
How to install and use Python in Git Bash for Windows? UPDATE: If the python command doesn’t work, try run this in git bash: alias python=’winpty python.exe’ Steps: 1. Download and install git for windows at: https://gitforwindows.org/ 2. Download and install Anaconda for windows at: https://www.anaconda.com/products/individual (scroll down a little and click the ‘Download’ button) 3. Open ‘Anaconda Prompt’ or ‘Git Bash’ and run: conda init bash If you are in ‘Git Bash’ run: echo ‘. $/.bash_profile’ > > /.bashrc N.B. I can’t put angled brackets in here. 4. Reopen ‘Git Bash’ and you should see (base) in the first line. Now you can run: ipython 5. That’s it! N.B. Leave comments below if it helped!
Показать больше
Войдите , чтобы оставлять комментарии
Configuring Git Bash to Run Python [For Windows]
If you are on Windows and choose to use Git Bash, you’ll need to run a few commands to configure it to run Python and Anaconda.
We’ll do this by creating a .bashrc file.
Open the Git Bash terminal and follow the steps below.
Step 1: Enter cd to get to your home directory.
This step is important. Git Bash does not open in this directory by default, and you’ll need to be here to create your .bashrc file.
Step 2: Enter pwd to get the path to your home directory.
pwd gives you the path to your current directory, which should be your home directory if you did Step 1. You’ll need this for the next step.
The path to my home directory is /c/Users/HP .
Step 3: Get the file path to your Anaconda installation.
To get the file path to your Anaconda installation, you need to take the path you got from the previous step and append to it with the name of your Anaconda folder.
Find the name of your Anaconda folder by entering ls . (These are lower case letters «l» and «s», because you want to «list» your files.) This should print all the file names in your home directory. If you used the default settings during your Anaconda installation, this folder name is likely Anaconda3 or anaconda .
In my directory, I had a folder named Anaconda3 . So the full file path to my Anaconda installation is /c/Users/HP/Anaconda3 .
Step 4: Add Python and Anaconda to PATH in .bashrc file.
Next, enter the following command in your terminal, replacing [YOUR_PATH] with the path to your Anaconda installation. For example, I would replace [YOUR PATH] in the string below with /c/Users/HP/Anaconda3 .
echo 'export PATH="$PATH:[YOUR_PATH]:[YOUR_PATH]/Scripts"' >> .bashrc
WARNING: Before pressing enter, make sure you are following the syntax exactly (especially the placement of each ‘ , » , and $ symbol), and double check that you are replacing [YOUR PATH] correctly. You can compare your complete command with mine in the screenshot below.
This step adds two paths to a .bashrc file, which tells Git Bash where to find the scripts it needs to execute Python and Anaconda. Again, it’s important that you are in your home directory when you complete this step.
Step 5: Add alias for Python in .bashrc file.
Next, enter this command to tell Git Bash where to find the Python executable file.
echo 'alias python="winpty python.exe"' >> .bashrc
This is an extra step that’s needed for users running Python in Git Bash. This adds a command to your .bashrc file that says to run winpty python.exe whenever you enter python into the terminal.
Step 6: Execute commands from .bashrc
Now that you added the necessary commands to your .bashrc file, run the following line to execute the file.
source .bashrc
Alternatively, you can just close and open a new Git Bash window, which would accomplish the same thing. .bashrc is executed every time Git Bash launches.
Step 7: Test Run
Run the following commands to make sure you can access conda, Python, and the Python interpreter. If you followed these steps correctly, you should now be able to run Python in Git Bash!
Enter exit() to leave the Python interpreter after the last step above.