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

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.

主站蜘蛛池模板: 从化市| 苍南县| 永德县| 平南县| 福泉市| 延安市| 将乐县| 叶城县| 九江市| 拉孜县| 丹江口市| 开江县| 卫辉市| 高邮市| 西青区| 临沭县| 阳泉市| 沙坪坝区| 松滋市| 盐亭县| 嘉峪关市| 朝阳区| 苏尼特右旗| 宿州市| 甘孜| 东方市| 贵港市| 独山县| 龙陵县| 南京市| 保山市| 瓮安县| 延川县| 离岛区| 读书| 两当县| 封丘县| 新乡县| 绥中县| 遂平县| 广州市|