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

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.

主站蜘蛛池模板: 万安县| 信宜市| 博乐市| 微博| 射阳县| 台南市| 哈尔滨市| 邵阳县| 新闻| 金华市| 文山县| 武汉市| 惠来县| 肥乡县| 玉环县| 和龙市| 华阴市| 五台县| 吴桥县| 宝清县| 朝阳市| 武邑县| 石泉县| 汨罗市| 昭通市| 洱源县| 唐河县| 瑞安市| 扎兰屯市| 涡阳县| 房山区| 会东县| 新乡县| 海兴县| 周至县| 安庆市| 和田县| 昌邑市| 浦城县| 彭阳县| 安阳县|