官术网_书友最值得收藏!

Installing Python

If you're a Windows or Mac user, you can download an installer directly from the Python website (https://www.python.org/downloads/). Pick the installer appropriate for your computer, download it, and run it for any platform. We also have the option of downloading the source code, compiling it, and installing Python that way.

Unix and Linux users, as well as Mac users who prefer it, have the option to install Python through their package manager instead. For systems which integrate a package manager, this is probably the best and easiest choice. If we use the package manager, this next part is probably already done, otherwise we need to make sure that the Python programs are able to run from the command line.

On macOS and Unix-like operating systems, all we need is to add a line to the profile or the bashrc file in our home directory:

  • macOS X (edit ~/.profile):
    export  PATH=<pydir>:$PATH
  • Unix/Linux (edit ~/.bashrc):
    export PATH=<pydir>:$PATH
  • Windows:
  1. Open Advanced System Settings in Control Panel.
  2. Click on Environments Variables....
  3. Edit PATH.
  4. Add ;<pydir> at the end.

Windows is only slightly more involved, as you'll need to open up the Control Panel and locate the Environment Variables screen. In each of the preceding examples, pydir is the directory where you installed Python—C:\python36, for example.

Once we've got the path environment variable set, we should be good to go. To check that-open a Terminal window (Command Prompt on Windows) and type Python, then hit Enter. If you don't know how to open the Terminal, don't worry, we'll talk about that in more detail in the next chapter.

Also, if you are a Unix user and you do not receive the correct result, it is potentially because the bashrc file or profile has not been executed yet. You may need to log out and log back in again.

If the Python interactive shell starts up when we type python into the Terminal, we're good to go. If it doesn't, go back to double-check the changes that we made to the path environment variable because that's the piece that tells the operating system where to look for programs.

That's it for setting up.

If you're feeling adventurous, you can experiment with the interactive shell that we just started up. Try typing in mathematical expressions and see what happens. In the next section, we'll look more closely at running Python code using the command line and the interactive shell.

主站蜘蛛池模板: 澳门| 常德市| 高陵县| 山丹县| 武胜县| 永春县| 克山县| 比如县| 含山县| 黄骅市| 兴义市| 固镇县| 安塞县| 丹阳市| 江达县| 新沂市| 柳林县| 托克逊县| 元阳县| 林甸县| 西昌市| 阿合奇县| 达拉特旗| 商都县| 英超| 当阳市| 宁南县| 石渠县| 旬邑县| 神木县| 姜堰市| 康平县| 庆阳市| 冀州市| 乌鲁木齐市| 韩城市| 南丰县| 宿迁市| 崇礼县| 郸城县| 讷河市|