python 环境 开发_设置Python开发环境

python 环境 开发

Setting up Python is usually simple, but there are some places where newcomers (and experienced users) need to be careful. What versions are there? What’s the difference between Python, CPython, Anaconda, PyPy? Those and many other questions may stump new developers, or people wanting to use Python.

设置Python通常很简单,但是在某些地方,新手(和经验丰富的用户)需要小心。 有什么版本? Python,CPython,Anaconda和PyPy有什么区别? 这些问题以及许多其他问题可能会困扰新开发人员或想要使用Python的人。

Note: this guide is opinionated.

注意:本指南是自以为是的。

Contents

内容

词汇表和问题 (Glossary and questions)

Python版本:2 vs 3 (Python versions: 2 vs 3)

The Python community has undergone sort of a schism in recent years. Python 3, released in 2008, broke backwards compatibility: deprecated some bad constructs and libraries (eg. raw_input() became input() and the original Python 2 function that ran code input by users is gone; print() became a function; many things that returned lists now are iterators — zip, range), and completely remodelled strings (which are now Unicode by default, and the interpreter behavior is stricter when the wrong type is used)

近年来,Python社区经历了种种分裂。 2008年发布的Python 3向后兼容:废弃了一些不良的构造和库(例如raw_input()变成了input() ,而原来运行用户输入代码的Python 2函数消失了; print()变成了一个函数;许多现在返回列表的是迭代器( ziprange )和完全重构的字符串(默认情况下现在为Unicode,并且使用错误类型时解释器的行为更加严格)

For new code, you should use Python 3. Most popular packages support Python 3, and many of them support both Pythons at the same time. The early bugs were ironed out in the first few point releases, some features that made porting easier were added (back).

对于新代码,您应该使用Python3。 大多数流行的软件包都支持Python 3 ,其中许多软件包同时支持两个Python。 早期的错误在前几个发行版中已得到解决,添加了一些使移植更容易的功能(返回)。

But what if you end up needing Python 2 later? No problem: you can learn the differences in a short time, and with the help of a few libraries (eg. six) you can easily write code that is compatible with Python 2 and 3 at the same time, using the same codebase (most libraries out there do that).

但是,如果您以后需要使用Python 2怎么办? 没问题:您可以在短时间内了解它们之间的区别,并且借助一些库(例如6个 ),您可以使用相同的代码库(大多数代码)轻松地同时编写与Python 2和3兼容的代码。图书馆在那里做)。

Python 2 will go EOL and lose official support and updates in 2020.

Python 2将停止销售,并在2020年失去官方支持和更新。

Read more: Python 2 or Python 3 on Python Wiki

阅读更多: Python Wiki上的Python 2或Python 3

我可以在同一台机器上运行多个Python吗? (Can I run multiple Pythons on the same machine?)

Yes. Note that multiple Python interpreters are completely separate: they have their own pip and packages, and you can’t run Python 2 code in a Python 3 interpreter. You need to specify which interpreter to use when installing packages and running some scripts (eg. pip2, pip3 or python3 -m pip).

是。 请注意,多个Python解释器是完全分开的:它们具有自己的pip和程序包,并且您无法在Python 3解释器中运行Python 2代码。 您需要指定在安装软件包和运行某些脚本(例如pip2pip3python3 -m pip )时使用的解释器。

It’s best to limit yourself to the latest Python 2 and 3 versions. Python is backwards-compatible within the major release, so Python 2.7 runs code written with older 2.x versions in mind.

最好限制自己使用最新的Python 2和3版本。 Python在主要版本中向后兼容,因此Python 2.7运行着考虑较早版本2.x编写的代码。

实作 (Implementations)

A programming language is an abstract construct. To run code written in that language, an interpreter or compiler needs to be written. In Python’s case, there’s a plethora of implementations. Some of them are:

编程语言是一种抽象构造。 要运行以该语言编写的代码,需要编写解释器或编译器。 在Python的情况下,有很多实现。 他们之中有一些是:

  • CPython is the reference implementation. This is the implementation distributed on https://python.org/ and as part of many operating systems. Most Python features are first implemented in CPython, and then they are ported to other implementations. If you don’t know what to choose, use CPython.
  • PyPy is a fast implementation, written in a subset of Python. It’s compatible with Python 2.7 and 3.5 (beta support). It can run all pure Python code, and many extension libraries that use CFFI.
  • IronPython is a .NET CLR implementation. It can integrate with .NET code.
  • Jython is a Java JVM implementation. It can integrate with Java code, as well as other JVM languages.
  • CPython是参考实现。 这是在https://python.org/上分发的实现,并且是许多操作系统的一部分。 大多数Python功能首先在CPython中实现,然后再移植到其他实现中。 如果您不知道选择什么,请使用CPython。
  • PyPy是一种快速实现,用Python的子集编写。 它与Python 2.7和3.5(测试版支持)兼容。 它可以运行所有纯Python代码以及许多使用CFFI的扩展库。
  • IronPython是.NET CLR实现。 它可以与.NET代码集成。
  • Jython是Java JVM实现。 它可以与Java代码以及其他JVM语言集成。

Read more: Python Implementations on Python Wiki

阅读更多: Python Wiki上的Python实现

发行版 (Distributions)

There are also Python (CPython) distributions. They ship the CPython interpreter and add some extra packages/features. They are maintained by other communities or corporate entities.

也有Python(CPython)发行版。 他们提供了CPython解释器,并添加了一些额外的包/功能。 它们由其他社区或公司实体维护。

The most popular third-party distribution is Anaconda from Continuum Analytics. It’s popular for data scientists, and includes over 100 packages, with extra pre-built binaries available from the conda package manager.

最受欢迎的第三方分发是Continuum Analytics的Anaconda 。 它对数据科学家来说很受欢迎,包括100多个软件包,以及conda软件包管理器提供的额外的预构建二进制文件。

I personally recommend to avoid Anaconda:

我个人建议避免Anaconda:

  • Most packages have binary wheels for Windows, macOS and Linux (yes, Linux!) making the installation as simple as pip install numpy.
  • You waste disk space for packages Anaconda installs that you won’t ever need.
  • It’s provided by some random for-profit company.
  • I’ve seen bugs that were not reproducible outside of Anaconda.
  • You can still do data science using the official distribution. There’s nothing special about Anaconda.
  • 大多数软件包都具有适用于Windows,macOS和Linux(是的Linux!)的二进制轮子,使安装就像pip install numpy一样简单。
  • 您浪费了磁盘空间来安装不需要的Anaconda安装软件包。
  • 它是由一些随机的营利性公司提供的。
  • 我见过在Anaconda之外无法复制的错误。
  • 您仍然可以使用官方发行版进行数据科学。 Anaconda没什么特别的。

Read more: Python distributions on Python Wiki

阅读更多: Python Wiki上的Python发行版

我可以从Python程序制作.exe文件吗? (Can I make .exe files from Python programs?)

Yes, you can. There are tools for this — PyInstaller is the best one. Note that you usually need to run it on the destination operating system. And remember that “compiling” to exe files like that is not a security measure — your source code is still easily recoverable. (It’s not a security measure in other languages either, even if getting source code back might be more expensive/tricky in those.)

是的你可以。 有一些工具可以实现— PyInstaller是最好的工具。 请注意,您通常需要在目标操作系统上运行它。 请记住,像这样“编译”到exe文件不是安全措施-您的源代码仍然易于恢复。 (即使使用其他语言,这也不是一种安全措施,即使重新获得源代码可能更昂贵/更麻烦。)

在哪里学习Python? 在哪里获得帮助? (Where to learn Python? Where to get help?)

The choice of learning material is important. If you get a bad book, it might discourage you from learning (because it’s boring), or may teach you bad/outdated practices.

学习材料的选择很重要。 如果您收到一本不好的书,它可能会阻止您学习(因为这很无聊),或者可能教给您不好的/过时的做法。

If you can already program in another language, I recommend the official Python tutorial. For newcomers to programming, I recommend Think Python or Automate the Boring Stuff with Python. They teach Python 3, and (mostly) best practices.

如果您已经可以使用另一种语言进行编程,建议您使用官方Python教程 。 对于刚开始编程的人,我建议使用Think Python使用Python自动完成无聊的事情 。 他们教Python 3和(大多数)最佳实践。

If you need help, try #python on freenode IRC, the Tutor or Python-list mailing lists, or a bunch of other communities. (I’m a regular on #python)

如果需要帮助, 在freenode IRC, TutorPython列表邮件列表或其他社区上尝试#python 。 (我是#python的常客

安装Python (Installing Python)

This guide will focus on installing CPython 2.7 and 3.x (latest), using the standard distribution. This choice is satisfactory for most people. Third-party distributions, while handy in some cases, are not needed for most. (See Distributions for arguments)

本指南将重点介绍使用标准发行版安装CPython 2.7和3.x(最新)。 这个选择对大多数人来说都是令人满意的。 第三方分发虽然在某些情况下很方便,但大多数情况下都不需要。 (请参阅分发以获取参数)

Throughout this guide, I’ll refer to the Python interpreter executable as python. The exact name depends on your system and desired version. On most OSes, python is Python 2 and python3 is 3; python2 should also exist. On Arch Linux, python is Python 3. On Windows, use the py launcher.

在本指南中,我将Python解释器可执行文件称为python 。 确切名称取决于您的系统和所需的版本。 在大多数操作系统上, python是Python 2,而python3是3。 python2也应该存在。 在Arch Linux上, python是Python3。在Windows上,使用py启动器。

视窗 (Windows)

Download the installer(s): https://www.python.org/downloads/

下载安装程序: https : //www.python.org/downloads/

Those installers come with pip, and modern Python 3.x versions come with the py launcher. You can use that launcher to pick a specific Python version, eg.:

这些安装程序带有pip ,而现代的Python 3.x版本带有py启动器。 您可以使用该启动器选择特定的Python版本,例如:

  • py -3 -m pip install <package>
  • py -2 somefile.py
  • py -2.7
  • py (default system version)
  • py -3 -m pip install <程序包>
  • py -2 somefile.py
  • py -2.7
  • py (默认系统版本)

It’s recommended for most use, and mandatory for upgrading pip.

建议将其用于大多数用途,并将其升级为必填项。

The 32-bit versions are more versatile. Most packages support both (the only exception I’m aware of is Tensorflow, which only allows 64-bit Python 3.5 as of now).

32位版本更加通用。 大多数软件包都支持这两种软件包(我所知道的唯一例外是Tensorflow,它目前仅支持64位Python 3.5)。

苹果系统 (macOS)

macOS ships with Python 2.7.10 (as of macOS Sierra). It’s not the latest version; it’s good enough for most people, but I still recommend installing your own (the system Python doesn’t include pip, for example). You can install the latest 2.7 version, as well as Python 3, using a package manager. I recommend Homebrew — it’s the most popular solution, and lets you install many other packages.

macOS随附Python 2.7.10(自macOS Sierra起)。 不是最新版本; 对于大多数人来说已经足够了,但是我仍然建议您安装自己的(例如,系统Python不包含pip )。 您可以使用包管理器来安装最新的2.7版本以及Python 3。 我推荐Homebrew-这是最受欢迎的解决方案,可让您安装许多其他软件包。

DO NOT use the python.org installers: they do not have uninstallers, so you will have outdated versions lying around after some time. There is no auto-update as well.

请勿使用python.org安装程序:它们没有卸载程序,因此一段时间后您将拥有过时的版本。 也没有自动更新。

If you already have a package manager installed (MacPorts, Fink), don’t install a new one and just use the existing one.

如果您已经安装了软件包管理器(MacPorts,Fink),则不要安装新的软件包管理器,而仅使用现有的软件包管理器。

  1. Install Homebrew.
  2. Run brew install python python3.
  3. You should now have python, python3, pip and pip3.
  1. 安装Homebrew
  2. 运行brew install python python3
  3. 您现在应该拥有pythonpython3pippip3

To update Homebrew and Python, run brew update.

要更新Homebrew和Python,请运行brew update

Linux(和其他类似Unix的操作系统) (Linux (and other Unix-like OSes))

On Linux, there usually are good enough packages in your OS repositories. You should be able to install the appropriate package for Python (2 and/or 3).

在Linux上,操作系统存储库中通常有足够好的软件包。 您应该能够为Python安装适当的软件包(2和/或3)。

If the version that ships with your distribution is too old, there are some options. There might be some repositories with better versions, eg. the deadsnakes PPA for Ubuntu. Then there’s the other option of compiling Python manually. The instructions depend on your exact requirements, but here’s a summary:

如果您的发行版附带的版本太旧,则有一些选择。 可能会有一些版本更好的存储库,例如。 适用于Ubuntu的死神PPA 。 然后还有另一个手动编译Python的选项。 这些说明取决于您的确切要求,但以下是摘要:

  1. Download the source distribution from Python.org and unpack it. Go into the unpacked source directory.
  2. Ensure you’ve got a functional C compiler and Python’s dependencies. You can usually use your system’s package manager to install the build dependencies of your system Python. Some dependencies are optional (eg. sqlite3 requires SQLite headers).
  3. Run ./configure --prefix=/opt/python3.6 and then make. (You may add other options to both. It will take a while.)
  4. Run make altinstall as root. Avoid make install, as it can override python executables.
  1. 从Python.org下载源代码发行版并解压缩。 进入解压后的源目录。
  2. 确保您具有功能良好的C编译器和Python的依赖项。 通常,您可以使用系统的软件包管理器来安装系统Python的构建依赖项。 一些依赖关系是可选的(例如, sqlite3需要SQLite标头)。
  3. 运行./configure --prefix = / opt / python3.6 ,然后制作 。 (您可以同时添加其他选项。这将需要一段时间。)
  4. 以root身份运行make altinstall 。 避免make install ,因为它可以覆盖python可执行文件。

Alternatively, you can try pyenv or pythonz — tools that can be used to install and manage different Python versions. Remember: compiling Python should be considered a last resort.

另外,您可以尝试使用pyenvpythonz-可用于安装和管理不同Python版本的工具。 请记住:编译Python应该被视为不得已

安装套件 (Installing packages)

To install third-party packages, you should use pip, the Python package manager. If you’re using Windows or macOS (from Homebrew), pip is included with your copy of Python. If you’re on Linux and installed Python from a system repository, install the correct system package (python-pip, python3-pip). If you compiled your own Python, pip is also included.

要安装第三方软件包,应使用Python软件包管理器pip。 如果您使用Windows或macOS(来自Homebrew),则Python副本中包含pip。 如果您使用的是Linux并从系统存储库中安装了Python,请安装正确的系统软件包( python-pippython3-pip )。 如果您编译自己的Python,还将包含pip。

To run pip, use py -m pip (Windows), python -m pip (other platforms), or the short pip/pip3 commands.

要运行pip,请使用py -m pip (Windows), python -m pip (其他平台)或简短的pip / pip3命令。

Very important: NEVER use sudo with pip. That can lead to conflicts with system package managers and does not provide isolation between package versions.

非常重要: 永远不要将sudo与pip一起使用 。 这可能导致与系统软件包管理器发生冲突,并且不能在软件包版本之间提供隔离。

Note that a package install is specific to the Python interpreter used to run pip. Packages installed to a virtualenv are separate from system packages; packages installed for “global” Python 2.7 are separate from 3.6 packages. Virtual environments generally don’t use the system packages, unless specifically enabled during creation.

请注意,软件包安装特定于用于运行pip的Python解释器。 安装到virtualenv的软件包与系统软件包是分开的; 为“全局” Python 2.7安装的软件包与3.6软件包是分开的。 虚拟环境通常不使用系统软件包,除非在创建过程中专门启用了这些软件包。

Some distros have pouplar packages in their repositories. Sometimes they’re good; in other cases they’re terribly outdated or they lack important components, making package managers angry and sick of supporting a 2-year-old version. (Especially since most bugs are closed with “we’ve fixed that long ago”)

一些发行版在其存储库中有pouplar软件包。 有时候他们很好。 在其他情况下,它们已经过时或缺少重要组件,从而使程序包管理者对支持2岁的版本感到愤怒和厌倦。 (特别是由于大多数错误已通过“我们很久以前已修复”而关闭)

用户安装 (User installs)

At a small scale, you can install packages with pip for a single user. Use pip install --user PACKAGE to do this. If your package installs scripts, they will be installed to ~/.local/bin on Linux, and ~/Library/Python/X.Y/bin on macOS (X.Y is Python version), or you can use python -m if the package supports it.

您可以在小范围内为单个用户安装带有pip的软件包。 使用pip install --user PACKAGE执行此操作。 如果您的软件包安装了脚本 ,则它们将被安装到Linux上的〜/ .local / bin和macOS上的〜/ Library / Python / XY / bin (XY是Python版本),或者如果软件包支持,则可以使用python -m它。

For most people and projects, virtual environments are better. There are, however, use cases for putting some packages user-wide — if you don’t work on projects, but instead are doing one-off research projects, those are better suited by user-wide installs.

对于大多数人和项目而言,虚拟环境更好。 但是,有一些用例可以在用户范围内放置某些软件包-如果您不从事项目工作,而是进行一次性研究项目,则这些软件包更适合于用户范围的安装。

虚拟环境 (Virtual environments)

Virtual environments are the best way to install and manage Python packages. Advantages include:

虚拟环境是安装和管理Python软件包的最佳方法。 优势包括:

  • Isolation of projects and their requirements: if one app/package requires library version X, but another requires version Y, they can live in separate virtual environments
  • Independent from system-wide packages
  • Lightweight (an empty virtualenv is about 10 MB)
  • Simple to re-create in any place (pip freeze > requirements.txtpip install -r requirements.txt)
  • 隔离项目及其要求:如果一个应用程序/程序包需要库版本X,而另一个需要库版本Y,则它们可以位于单独的虚拟环境中
  • 独立于系统范围的软件包
  • 轻量级(一个空的virtualenv约为10 MB)
  • 易于在任何地方重新创建( pip冻结> requirements.txtpip install -r requirements.txt
工具与管理 (Tools and management)

There are two tools to facilitate creation of virtual environments: the older virtualenv project, and the newer venv module. The venv module is shipped with Python 3.x; some distributions may put it in a separate package or remove it altogether. I recommend using virtualenv — it’s compatible with more Python versions (it’s better to use the same tool for both Pythons) and cannot be broken by incompetent OS package mainainers (venv fails on Debian due to no ensurepip; there is a python3-venv package that fixes it but that’s hard to discover)

有两种工具可以帮助创建虚拟环境:较旧的virtualenv项目和较新的venv模块。 venv模块随Python 3.x一起提供; 有些发行版可能会将其放在单独的包装中或将其完全删除。 我建议使用virtualenv -它与更多Python版本兼容(最好对两个Python使用相同的工具),并且不能被不称职的OS软件包维护者破坏(由于没有surepipvenv在Debian上失败;有一个python3-venv软件包修复它,但很难发现)

There are multiple schools of thought regarding virtualenv placement and content. Myself, I use virtualenvwrapper to manage virtualenvs and put them in ~/virtualenvs. Other people put virtualenvs inside their git repositories (but they must be in .gitignore) Virtualenvs should only contain packages installed with pip so they can be rereated quickly.

关于virtualenv的放置和内容有多种思路。 我自己使用virtualenvwrapper来管理virtualenvs并将它们放入〜/ virtualenvs中 。 其他人将virtualenvs放入其git存储库中(但必须位于.gitignore中 )Virtualenvs仅应包含pip安装的软件包,以便可以快速重新创建它们。

I also use the virtualenvwrapper plugin for Oh My Zsh, which also activates virtualenvs with the same name as a git repo, or the environment named by a .venv file.

我还使用了适用于Oh My Zsh的virtualenvwrapper插件,该插件还激活了与git repo相同名称或.venv文件命名的环境的virtualenvs

安装及使用 (Installation and usage)

To install virtualenv user-wide, use pip install --user virtualenv. You can then use it with python -m virtualenv DIRECTORY. You may pass extra options, eg. interpreter to use (-p python3). Sometimes you need to install virtualenv for every Python version; usually, one copy is enough.

要在整个用户范围内安装virtualenv,请使用pip install --user virtualenv 。 然后,您可以将其与python -m virtualenv DIRECTORY一起使用 。 您可能会传递其他选项,例如。 使用的解释器( -p python3 )。 有时您需要为每个Python版本安装virtualenv; 通常,一份就足够了。

How to use them? This is a subject of heated debate in the Python community. Some people believe that activating (source bin/activate on *nix; Scriptsactivate on Windows) is the right thing to do. Others think that you should use bin/python (or other scripts in that directory) directly. Others still think virtualenvs should be used in subshells. In my opinion, if activating virtualenvs works in your environment, you should do it — it’s the most convenient option. There are, however, cases when activation fails, or is otherwise impossible — calling bin/python directly is your best bet in that case. I’m not a fan of the subshell option, because it complicates stuff if you work on multiple projects, and requires tracking usage manually.

如何使用它们? 这是Python社区中激烈辩论的主题。 有人认为激活(在* nix上为source bin / activate ;在Windows上为Scriptsactivate )是正确的做法。 其他人则认为您应该直接使用bin / python (或该目录中的其他脚本)。 其他人仍然认为virtualenvs应该在子shell中使用 。 我认为,如果激活virtualenvs在您的环境中可行,那么您应该这样做-这是最方便的选择。 但是,在某些情况下,激活失败或否则是不可能的-在这种情况下,直接调用bin / python是最好的选择。 我不喜欢subshel​​l选项,因为如果您在多个项目上工作,它会使事情变得复杂,并且需要手动跟踪使用情况。

升级和移动 (Upgrading and moving)

Upgrading the system Python may make your virtualenvs unusable. For patch version upgrades, you can just update symlinks (see fix-venvs.sh). However, if the minor version changes, it’s best to re-create the virtualenv (you need to create requirements.txt ahead of time).

升级系统Python可能会使您的virtualenv无法使用。 对于补丁程序版本升级,您可以仅更新符号链接(请参阅fix-venvs.sh )。 但是,如果次要版本发生更改,则最好重新创建virtualenv(您需要提前创建requirements.txt )。

You cannot move a virtualenv between directories/machines or rename virtualenvs. You need to use pip freeze > requirements.txt, create a new virtualenv, and run pip install -r requirements.txt (you can then delete the old environment with a simple rm -rf)

您不能在目录/机器之间移动virtualenv或重命名virtualenvs。 您需要使用pip Frozen> requirements.txt ,创建一个新的virtualenv,然后运行pip install -r requirements.txt (然后可以使用简单的rm -rf删除旧环境)

具有C扩展名的软件包(二进制) (Packages with C extensions (binary))

The situation improved drastically in the past year or so. Nowadays, almost all packages have a pre-compiled package available in PyPI. Those packages work for Windows, macOS, and Linux. There are packages for some of the most common offenders, including Pillow, lxml, PyQt5, numpy… However, there might still be packages without wheels on PyPI.

在过去一年左右的时间里,情况大为改善。 如今,几乎所有软件包都在PyPI中提供了预编译的软件包。 这些软件包适用于Windows,macOS和Linux。 有一些针对一些最常见违规者的软件包,包括Pillow,lxml,PyQt5,numpy…。但是,在PyPI上可能仍然没有软件包。

If there is no wheel for a package and you are on Windows, check out Christoph Gohlke’s unofficial binaries. If you can’t find any wheels online, you would have to resort to compiling it manually — this requires installign Visual Studio in a version that matches your Python, and it’s kind of a pain to do.

如果没有包装袋的轮子,而您正在使用Windows,请查看Christoph Gohlke的非官方二进制文件 。 如果您在网上找不到任何轮子,则必须求助于手动编译-这需要在与Python相匹配的版本中安装Visual Studio,这很麻烦。

If you are not on Windows, you must install a C compiler and toolchain. If you get a warning about missing Python.h, install the appropriate development package — for example, python-dev or python3-dev) on Debian/Ubuntu, python-devel or python3-devel on RHEL/Fedora. The package you’re trying to install might have other dependencies that you need to install (the -dev(el) part is important, too)

如果您不在Windows上,则必须安装C编译器和工具链。 如果您收到有关缺少Python.h的警告,请在Debian / Ubuntu上安装适当的开发包-例如python-devpython3-dev ,在RHEL / Fedora上安装python-develpython3-devel 。 您要安装的软件包可能还需要安装其他依赖项( -dev(el)部分也很重要)

其他的东西 (Other stuff)

If you’re working on a project, use pip install -e . inside the project directory to install the package in your environment in development (editable) mode. This loads code directly from your repository — you don’t need to re-install on every change; you might need to re-install when your version number changes.

如果您正在处理项目,请使用pip install -e 在项目目录中以开发(可编辑)模式在您的环境中安装软件包。 这将直接从您的存储库中加载代码-您无需在每次更改时都重新安装; 版本号更改时,您可能需要重新安装。

编辑器和IDE (Editors and IDEs)

Another important thing a developer should take care of is the choice of an editor. This is an important decision, and is the reason for many holy wars in the programmer community.

开发人员应注意的另一重要事项是选择编辑器。 这是一个重要的决定,并且是程序员社区中发生许多圣战的原因。

A good editor should have syntax highlighting for all languages you need to work with. It should also have features like visual block/multiple selections, sophisticated find-and-replace, file finding, code completion, and many more minor but helpful features.

好的编辑器应突出显示您需要使用的所有语言的语法。 它还应具有可视块/多项选择,复杂的查找和替换,文件查找,代码完成以及许多次要但有用的功能。

Then there’s the difference between IDEs and text editors. Text editors are simpler, whereas IDEs try to include many extra things not necessairly related to writing code. IDEs often use more resources, but you won’t notice it with a modern computer (especially with a SSD).

然后是IDE和文本编辑器之间的区别。 文本编辑器更简单,而IDE尝试包含许多不必要的与编写代码无关的内容。 IDE通常会使用更多的资源,但是您不会在现代计算机(尤其是SSD)上注意到它。

I spend the most of my time in Vim (neovim/VimR to be precise). Vim is the most powerful text editor out there, and with the right set of plugins it can beat IDEs at speed and productivity. Vim has a steep learning curve, but it’s worth it — you can do large changes with just a few keystrokes. Vim is considered so good that many IDEs (Visual Studio, IntelliJ IDEA/PyCharm) have (mediocre) Vim emulation plugins.

我将大部分时间都花在Vim上准确地说是neovim / VimR )。 Vim是目前功能最强大的文本编辑器,并且通过正确的插件集,它可以在速度和生产率上击败IDE。 Vim的学习曲线很陡,但这是值得的-您只需几次按键就可以进行大的更改。 Vim被认为是如此出色,以至于许多IDE(Visual Studio,IntelliJ IDEA / PyCharm)都具有(中等)Vim仿真插件。

However, if you would prefer an IDE, your best bet would be PyCharm from JetBrains. It has both a free Community and paid Professional edition. The JetBrains folks are experts at IDEs — they have fully-fledged tools for many languages. Their Python solution offers a plethora of options that aid programmers in their work. If you’re on Windows, you might try Python Tools for Visual Studio (although I haven’t worked with that and can’t vouch for it)

但是,如果您更喜欢IDE,那么最好的选择是JetBrains的PyCharm 。 它既有免费的社区版,又有付费的专业版。 JetBrains的人员是IDE的专家-他们拥有适用于多种语言的成熟工具。 他们的Python解决方案提供了许多选项,可帮助程序员进行工作。 如果您使用的是Windows,则可以尝试使用适用于Visual Studio的Python工具(尽管我还没有使用过它,也无法为其提供担保)

Another, lighter option is Visual Studio Code — it’s a text editor, but can offer many IDE-like features with the right set of plugins. It’s Electron-based architecture, or effectively being based on top of Google’s Chromium, is unfortunate and can lead to bad performance on lower-end machines. (In my experience, it’s better than Atom.) You can also try Sublime Text ($70).

另一个更简单的选择是Visual Studio Code-这是一个文本编辑器,但可以通过正确的插件集提供许多类似IDE的功能。 它是基于电子的架构,或者实际上是基于Google Chromium的架构,很不幸,并且可能导致低端计算机的性能下降。 (以我的经验,它比Atom好。)您还可以尝试Sublime Text (70美元)。

But really, almost any editor will do. But please avoid IDLE, the editor included with Python. It lacks some of the most basic things — it doesn’t even have an option to show line numbers. Not to mention its ugliness. Also, don’t use Notepad and TextEdit. Those are too simple, and Notepad has encoding issues.

但实际上,几乎所有编辑器都可以。 但是请避免使用 IDLE(Python附带的编辑器)。 它缺少一些最基本的内容-甚至没有显示行号的选项。 更不用说它的丑陋了。 另外,请勿使用记事本和TextEdit。 这些太简单了,记事本有编码问题。

翻译自: https://www.pybloggers.com/2017/07/setting-up-a-python-development-environment/

python 环境 开发

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值