Как установить 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
Получите крутое код-ревью от практикующих программистов с разбором ошибок и рекомендациями, на что обратить внимание — бесплатно.
Переходите на страницу учебных модулей «Девмана» и выбирайте тему.
Install Git, Bash Shell, Python
This page outlines the tools and resources that you will need to install Git, Bash and Python applications onto your computer as the first step of our Python skills tutorial series.
Checklist
Detailed directions to accomplish each objective are below.
- Install Bash shell (or shell of preference)
- Install Git
- Install Python 3.x
Bash/Shell Setup
Install Bash for Windows
- Download the Git for Windows installer.
- Run the installer and follow the steps bellow:
- Welcome to the Git Setup Wizard: Click on «Next».
- Information: Click on «Next».
- Select Destination Location: Click on «Next».
- Select Components: Click on «Next».
- Select Start Menu Folder: Click on «Next».
- Adjusting your PATH environment: Select «Use Git from the Windows Command Prompt» and click on «Next». If you forgot to do this programs that you need for the event will not work properly. If this happens rerun the installer and select the appropriate option.
- Configuring the line ending conversions: Click on «Next». Keep «Checkout Windows-style, commit Unix-style line endings» selected.
- Configuring the terminal emulator to use with Git Bash: Select «Use Windows’ default console window» and click on «Next».
- Configuring experimental performance tweaks: Click on «Next».
- Completing the Git Setup Wizard: Click on «Finish».
This will provide you with both Git and Bash in the Git Bash program.
Install Bash for Mac OS X
The default shell in all versions of Mac OS X is bash, so no need to install anything. You access bash from the Terminal (found in /Applications/Utilities ). You may want to keep Terminal in your dock for this workshop.
Install Bash for Linux
The default shell is usually Bash, but if your machine is set up differently you can run it by opening a terminal and typing bash . There is no need to install anything.
Git Setup
Git is a version control system that lets you track who made changes to what when and has options for easily updating a shared or public version of your code on GitHub. You will need a supported web browser (current versions of Chrome, Firefox or Safari, or Internet Explorer version 9 or above).
Git installation instructions borrowed and modified from Software Carpentry.
Git for Windows
Git should be installed on your computer as part of your Bash install.
Git on Mac OS X
Install Git on Macs by downloading and running the most recent installer for «mavericks» if you are using OS X 10.9 and higher -or- if using an earlier OS X, choose the most recent «snow leopard» installer, from this list. After installing Git, there will not be anything in your /Applications folder, as Git is a command line program.
**Data Tip:** If you are running Mac OSX El Capitan, you might encounter errors when trying to use git. Make sure you update XCODE. Read more — a Stack Overflow Issue.
Git on Linux
If Git is not already available on your machine you can try to install it via your distro’s package manager. For Debian/Ubuntu run sudo apt-get install git and for Fedora run sudo yum install git .
Setting Up Python
Python is a popular language for scientific computing and data science, as well as being a great for general-purpose programming. Installing all of the scientific packages individually can be a bit difficult, so we recommend using an all-in-one installer, like Anaconda.
Regardless of how you choose to install it, **please make sure your environment is set up with Python version 3.7 (at the time of writing, the gdal package did not work with the newest Python version 3.6). Python 2.x is quite different from Python 3.x so you do need to install 3.x and set up with the 3.7 environment.
We will teach using Python in the Jupyter Notebook environment, a programming environment that runs in a web browser. For this to work you will need a reasonably up-to-date browser. The current versions of the Chrome, Safari and Firefox browsers are all supported (some older browsers, including Internet Explorer version 9 and below, are not). You can choose to not use notebooks in the course, however, we do recommend you download and install the library so that you can explore this tool.
Windows
Download and install Anaconda. Download the default Python 3 installer (3.7). Use all of the defaults for installation except make sure to check Make Anaconda the default Python.
Mac OS X
Download and install Anaconda. Download the Python 3.x installer, choosing either the graphical installer or the command-line installer (3.7). For the graphical installer, use all of the defaults for installation. For the command-line installer open Terminal, navigate to the directory with the download then enter:
bash Anaconda3-2020.11-MacOSX-x86_64.sh (or whatever you file name is)
Linux
Download and install Anaconda. Download the installer that matches your operating system and save it in your home folder. Download the default Python 3 installer.
Open a terminal window and navigate to your downloads folder. Type
and then press tab. The name of the file you just downloaded should appear.
Press enter. You will follow the text-only prompts. When there is a colon at the bottom of the screen press the down arrow to move down through the text. Type yes and press enter to approve the license. Press enter to approve the default location for the files. Type yes and press enter to prepend Anaconda to your PATH (this makes the Anaconda distribution the default Python).
Install Python packages
We need to install several packages to the Python environment to be able to work with the remote sensing data
If you are new to working with command line you may wish to complete the next setup instructions which provides and intro to command line (bash) prior to completing these package installation instructions.
Windows
Create a new Python 3.7 environment by opening Windows Command Prompt and typing
conda create –n py37 python=3.7 anaconda
When prompted, activate the py37 environment in Command Prompt by typing
You should see (py37) at the beginning of the command line. You can also test that you are using the correct version by typing python —version .
Install Python package(s):
- gdal: conda install gdal
- h5py: conda install h5py
Note: You may need to only install gdal as the others may be included in the default.
Mac OS X
Create a new Python 3.7 environment by opening Terminal and typing
conda create –n py37 python=3.7 anaconda
This may take a minute or two.
When prompted, activate the py37 environment in Command Prompt by typing
source activate py37
You should see (py37) at the beginning of the command line. You can also test that you are using the correct version by typing python —version .
Install Python package(s):
- gdal: conda install gdal
- h5py: conda install h5py
Linux
Open default terminal application (on Ubuntu that will be gnome-terminal).
Install Python package(s):
- gdal: conda install gdal
- h5py: conda install h5py
Set up Jupyter Notebook Environment
In your terminal application, navigate to the directory ( cd ) that where you want the Jupyter Notebooks to be saved (or where they already exist).
Open Jupyter Notebook with
Once the notebook is open, check which version of Python you are in by using the prompts
# check what version of Python you are using. import sys sys.versionYou should now be able to work in the notebook.
The gdal package that occasionally has problems with some versions of Python. Therefore test out loading it using
Additional Resources
- Setting up the Python Environment section from the Python Bootcamp
- Conda Help: setting up an environment
- iPython documentation: Kernals
Как установить ipython через git bash
Tony Heller at realclimatescience dotcom hands out Python programs for graphing thermometer readings. Links to official databases let you download the data, but I could never get the other part to load and graph it. Before long, Google began threatening to delete my Google Drive data while refusing my offer of payment for more space. I was finally bullied into deleting the databases and that ended the noble experiment. If you’re looking for material, a how-to guide might be good for an article. Like Like
GOOOOOOGLE. says:
Wtf are you on about? Lol. Like Like
How to add more to Git Bash on Windows
Git for Windows comes bundled with the «Git Bash» terminal which is incredibly handy for unix-like commands on a windows machine. It is missing a few standard linux utilities, but it is easy to add ones that have a windows binary available.
The basic idea is that C:\Program Files\Git\mingw64\ is your / directory according to Git Bash (note: depending on how you installed it, the directory might be different. from the start menu, right click on the Git Bash icon and open file location. It might be something like C:\Users\name\AppData\Local\Programs\Git , the mingw64 in this directory is your root. Find it by using pwd -W ). If you go to that directory, you will find the typical linux root folder structure ( bin , etc , lib and so on).
If you are missing a utility, such as wget, track down a binary for windows and copy the files to the corresponding directories. Sometimes the windows binary have funny prefixes, so you should rename the .exe file to the standard name. Since bin is on the PATH, it will be automatically available to Git Bash.
Note: Many interactive utilities, such as python , ipython or nano , will not display properly with Git Bash’s mintty terminal. Try invoking them with winpty instead, for example winpty ipython will work nicely. The Git-for-Windows team is focused on supporting Git, not a full UNIX shell environment. If you are interested in more complete package with build tools, check my notes on Cygwin or Cmder—or install Windows Subsystem for Linux or WSL2.
Here are some utilities to add:
Wget
- Download the lastest wget binary for windows from eternallybored (they are available as a zip with documentation, or just an exe)
- If you downloaded the zip, extract all (if windows built in zip utility gives an error, use 7-zip).
- Rename the file wget64.exe to wget.exe if necessary.
- Move wget.exe to your Git\mingw64\bin\ .
Note: I have noticed some bugs when using Wget on Git Bash to create WARC files. For more complex use of Wget, consider Cygwin instead.
Hugo
Hugo static site generator can be downloaded as a binary and does not have a installer. Dropping it into your bin easily adds it to your Git Bash path. Grab the Windows 64-bit version from the releases page. Unzip the download, then copy hugo.exe into your Git\mingw64\bin directory.
Xpdf
Xpdf is a handy utility for manipulating PDF files.
- Download the windows version «Xpdf tools».
- Extract zip.
- Copy the contents of xpdf-tools-win-4.00\bin64\ into your Git\mingw64\bin\ .
- Check the docs to get started with tools such as pdftotext and pdftopng .
ExifTool
- Download the «stand-alone Windows Executable» from the ExifTool page (this will be a .zip file e.g. «exiftool-11.99.zip»).
- Unzip the downloaded file.
- Inside you will find a file named exiftool(-k).exe . Rename it to exiftool.exe .
- Move exiftool.exe to your Git\mingw64\bin\ .
Other possibilities
Most utilities that provide binary releases for Windows can be added to GitBash following the same pattern. Here are some more handy examples:
make
Keep in mind you can easy add make , but it doesn’t come packaged with all the standard UNIX build toolchain—so you will have to ensure those are installed and on your PATH, or you will encounter endless error messages.
- Go to ezwinports.
- Download make-4.1-2-without-guile-w32-bin.zip (get the version without guile).
- Extract zip.
- Copy the contents to your Git\mingw64\ merging the folders, but do NOT overwrite/replace any existing files.
Nano
As of 2018, recent versions of Git Bash include Nano, so this is unnecessary! Just be sure to choose Nano as your default editor when installing Git for Windows.
- Download the Nano binary from Nano win32-support page. You just need the .exe file, which is named nano-git-0d9a7347243.exe (as of this writing).
- Rename the file to nano.exe , and copy to the mingw64\bin directory.
- This version of Nano will not work with Git Bash alone, but can be invoked using winpty , for example, winpty nano test.txt .