标签归档:windows

错误:找不到vcvarsall.bat

问题:错误:找不到vcvarsall.bat

我试图安装Python软件包dulwich

pip install dulwich

但是我收到了一个神秘的错误消息:

error: Unable to find vcvarsall.bat

如果我尝试手动安装软件包,也会发生相同的情况:

> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat

I tried to install the Python package dulwich:

pip install dulwich

But I get a cryptic error message:

error: Unable to find vcvarsall.bat

The same happens if I try installing the package manually:

> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat

回答 0

更新:评论指出此处的说明可能很危险。考虑使用Visual C ++ 2008 Express版或专用于Python的Microsoft Visual C ++编译器详细信息),而不要使用下面的原始答案。原始错误消息表示未安装所需的Visual C ++版本。


对于Windows安装:

在运行setup.py进行软件包安装时,Python 2.7搜索已安装的Visual Studio2008。您可以通过VS90COMNTOOLS在调用之前在环境变量中设置正确的路径来诱使Python使用更新的Visual Studio setup.py

根据安装的Visual Studio版本执行以下命令:

  • Visual Studio 2010(VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012(VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013(VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015(VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS%

警告:如下所述,如果您尝试编译python模块,则此答案不太可能起作用。

有关详细信息,请参见在Windows上为Python 2.7构建lxml

Update: Comments point out that the instructions here may be dangerous. Consider using the Visual C++ 2008 Express edition or the purpose-built Microsoft Visual C++ Compiler for Python (details) and NOT using the original answer below. Original error message means the required version of Visual C++ is not installed.


For Windows installations:

While running setup.py for package installations, Python 2.7 searches for an installed Visual Studio 2008. You can trick Python to use a newer Visual Studio by setting the correct path in VS90COMNTOOLS environment variable before calling setup.py.

Execute the following command based on the version of Visual Studio installed:

  • Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015 (VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS%

WARNING: As noted below, this answer is unlikely to work if you are trying to compile python modules.

See Building lxml for Python 2.7 on Windows for details.


回答 1

我找到了解决方案。我安装了“ amara”时遇到了完全相同的问题,并且出现了错误。我安装了mingw32,但需要配置distutils。

  1. 我已经安装了Python 2.6。
  2. 我安装了mingw32 C:\programs\mingw\
  3. 将mingw32的bin目录添加到您的环境变量中:附加c:\programs\MinGW\bin;PATH
  4. 编辑位于以下位置的distutils.cfg文件(如果不存在则创建)C:\Python26\Lib\distutils\distutils.cfg

    [build]
    compiler=mingw32
  5. 现在运行easy_install.exe amara

确保通过打开新环境来设置环境cmd.exe

I found the solution. I had the exact same problem, and error, installing ‘amara’. I had mingw32 installed, but distutils needed to be configured.

  1. I have Python 2.6 that was already installed.
  2. I installed mingw32 to C:\programs\mingw\
  3. Add mingw32’s bin directory to your environment variable: append c:\programs\MinGW\bin; to the PATH
  4. Edit (create if not existing) distutils.cfg file located at C:\Python26\Lib\distutils\distutils.cfg to be:

    [build]
    compiler=mingw32
    
  5. Now run easy_install.exe amara.

Make sure environment is set by opening a new cmd.exe.


回答 2

您可以从http://www.lfd.uci.edu/~gohlke/pythonlibs/安装编译版本


回答 3

如果要使用Visual Studio C ++而不是mingw进行编译…

  1. 运行python.exe以显示使用哪个版本的VC ++(如下所示的示例)。

    它是重要的使用Visual C ++编译器的相应版本的Python用,因为编译distilutilsget_build_version防止混合版本(每彼得的警告)。

    • 黄色(顶部)是使用MSC v.1500(Visual Studio C ++ 2008)编译的Python 2.7。
    • 红色(底部)是使用MSC v.1600(Visual Studio C ++ 2010)编译的Python 3.4.1。

  2. 使用下表[1]将内部VC ++版本与相应的Visual Studio版本进行匹配:

    MSC v.1000 -> Visual C++ 4.x        
    MSC v.1100 -> Visual C++ 5          
    MSC v.1200 -> Visual C++ 6          
    MSC v.1300 -> Visual C++ .NET       
    MSC v.1310 -> Visual C++ .NET 2003  
    MSC v.1400 -> Visual C++ 2005  (8.0)
    MSC v.1500 -> Visual C++ 2008  (9.0)
    MSC v.1600 -> Visual C++ 2010 (10.0)
    MSC v.1700 -> Visual C++ 2012 (11.0)
    MSC v.1800 -> Visual C++ 2013 (12.0)
    MSC v.1900 -> Visual C++ 2015 (14.0)
    MSC v.1910 -> Visual C++ 2017 (15.0)
    MSC v.1911 -> Visual C++ 2017 (15.3)
    MSC v.1912 -> Visual C++ 2017 (15.5)
    MSC v.1913 -> Visual C++ 2017 (15.6)
    MSC v.1914 -> Visual C++ 2017 (15.7)
    MSC v.1915 -> Visual C++ 2017 (15.8)
    MSC v.1916 -> Visual C++ 2017 (15.9)   
  3. 从上一步下载并安装相应版本的Visual Studio C ++。
    下面列出了特定版本VC ++的其他说明。

    Visual Studio C ++ 2008的注意事项

    对于只有 32位编译器,下载的Visual Studio C ++ 2008 Express版本

    对于64位编译器[2] [3],请下载Windows 7的Windows SDK和.NET Framework 3.5 SP1

    • 取消选中所有选项,Developer Tools >> Visual C++ Compilers以节省安装SDK工具所需的时间和磁盘空间,否则就不需要使用SDK工具。

    Visual Studio C ++ 2010的注意事项

    根据Microsoft的说法,如果安装了Visual Studio 2010 SP1,则可能已删除VC ++的编译器和库。
    如果是这种情况,请下载Visual C ++ 2010 SP1编译器更新

    Visual Studio C ++ 2015的注意事项

    如果不需要Visual Studio IDE,请下载Visual Studio C ++ 2015构建工具

    Visual Studio C ++ 2017的注意事项

    如果您不需要Visual Studio IDE,请下载Visual Studio 2017的构建工具

    建议:如果您同时安装了32位和64位Python,则可能还希望使用virtualenv创建单独的Python环境,以便一次可以使用一个或另一个,而无需弄乱选择要使用哪个Python版本的路径。采用。

根据@srodriguex的说法,您可以通过遵循以下答案,而不是将一些批处理文件复制到Python正在搜索的位置,从而跳过手动加载批处理文件的步骤(步骤4-6)。如果这不起作用,请执行以下最初对我有用的步骤。

  1. 开一个 cmd.exe

  2. 尝试安装需要C扩展的东西之前,请运行以下批处理文件以将VC ++编译器的环境加载到会话中(即环境变量,编译器的路径等)。

    执行:

    • 32位编译器:

      注意:32位Windows安装将仅C:\Program Files\符合预期

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"

    • 64位编译器:

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"

      注意:是的,本机64位编译器位于中Program Files (x86)。不要问我为什么。
      此外,如果您想知道vcvars64.bat和之间的区别,vcvarsx86_amd64.bat或者更重要的是amd64和之间的区别x86_amd64,则前者用于本机64位编译器工具,而后者是可以在32位Windows安装上运行的64位交叉编译器。 。

    更新:
    如果由于某种原因你得到error: ... was unexpected at this time.其中的...一些一系列字符,那么你需要检查你的路径变量没有任何多余的字符,如额外的报价或杂散字符。如果批处理文件最初没有意义,则将无法更新您的会话路径。

  3. 如果一切顺利,则应根据以下版本的VC ++和运行的命令获得以下消息之一:

    对于32位编译器工具:
    Setting environment for using Microsoft Visual Studio 20xx x86 tools.

    对于64位编译器工具:
    Setting environment for using Microsoft Visual Studio 20xx x64 tools.

  4. 现在,通过python setup.py install或运行设置pip install pkg-name

  5. 希望并用手指指望行星正确对齐,以使VC ++能够合作。

If you want to compile with Visual Studio C++ instead of mingw…

  1. Run python.exe to display which version of VC++ it was compiled with (example shown below).

    It is important to use the corresponding version of the Visual C++ compiler that Python was compiled with since distilutils‘s get_build_version prevents mixing versions (per Piotr’s warning).

    • Yellow (top) is Python 2.7, compiled with MSC v.1500 (Visual Studio C++ 2008)
    • Red (bottom) is Python 3.4.1, compiled with MSC v.1600 (Visual Studio C++ 2010)

  2. Use the table below[1] to match the internal VC++ version with the corresponding Visual Studio release:

    MSC v.1000 -> Visual C++ 4.x        
    MSC v.1100 -> Visual C++ 5          
    MSC v.1200 -> Visual C++ 6          
    MSC v.1300 -> Visual C++ .NET       
    MSC v.1310 -> Visual C++ .NET 2003  
    MSC v.1400 -> Visual C++ 2005  (8.0)
    MSC v.1500 -> Visual C++ 2008  (9.0)
    MSC v.1600 -> Visual C++ 2010 (10.0)
    MSC v.1700 -> Visual C++ 2012 (11.0)
    MSC v.1800 -> Visual C++ 2013 (12.0)
    MSC v.1900 -> Visual C++ 2015 (14.0)
    MSC v.1910 -> Visual C++ 2017 (15.0)
    MSC v.1911 -> Visual C++ 2017 (15.3)
    MSC v.1912 -> Visual C++ 2017 (15.5)
    MSC v.1913 -> Visual C++ 2017 (15.6)
    MSC v.1914 -> Visual C++ 2017 (15.7)
    MSC v.1915 -> Visual C++ 2017 (15.8)
    MSC v.1916 -> Visual C++ 2017 (15.9)   
    
  3. Download and install the corresponding version of Visual Studio C++ from the previous step.
    Additional notes for specific versions of VC++ are listed below.

    Notes for Visual Studio C++ 2008

    For only the 32-bit compilers, download Visual Studio C++ 2008 Express Edition.

    For the 64-bit compilers[2][3], download Windows SDK for Windows 7 and .NET Framework 3.5 SP1.

    • Uncheck everything except Developer Tools >> Visual C++ Compilers to save time and disk space from installing SDK tools you otherwise don’t need.

    Notes for Visual Studio C++ 2010

    According to Microsoft, if you installed Visual Studio 2010 SP1, it may have removed the compilers and libraries for VC++.
    If that is the case, download Visual C++ 2010 SP1 Compiler Update.

    Notes for Visual Studio C++ 2015

    If you don’t need the Visual Studio IDE, download Visual Studio C++ 2015 Build Tools.

    Notes for Visual Studio C++ 2017

    If you don’t need the Visual Studio IDE, download Build Tools for Visual Studio 2017.

    Suggestion: If you have both a 32- and 64-bit Python installation, you may also want to use virtualenv to create separate Python environments so you can use one or the other at a time without messing with your path to choose which Python version to use.

According to @srodriguex, you may be able to skip manually loading the batch file (Steps 4-6) by instead copying a few batch files to where Python is searching by following this answer. If that doesn’t work, here are the following steps that originally worked for me.

  1. Open up a cmd.exe

  2. Before you try installing something which requires C extensions, run the following batch file to load the VC++ compiler’s environment into the session (i.e. environment variables, the path to the compiler, etc).

    Execute:

    • 32-bit Compilers:

      Note: 32-bit Windows installs will only have C:\Program Files\ as expected

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"

    • 64-bit Compilers:

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"

      Note: Yes, the native 64-bit compilers are in Program Files (x86). Don’t ask me why.
      Additionally, if you are wondering what the difference between vcvars64.bat and vcvarsx86_amd64.bat or more importantly the difference between amd64 and x86_amd64, the former are for the native 64-bit compiler tools and the latter are the 64-bit cross compilers that can run on a 32-bit Windows installation.

    Update:
    If for some reason you are getting error: ... was unexpected at this time. where the ... is some series of characters, then you need to check that you path variable does not have any extraneous characters like extra quotations or stray characters. The batch file is not going to be able to update your session path if it can’t make sense of it in the first place.

  3. If that went well, you should get one of the following messages depending on which version of VC++ and which command you ran:

    For the 32-bit compiler tools:
    Setting environment for using Microsoft Visual Studio 20xx x86 tools.

    For the 64-bit compiler tools:
    Setting environment for using Microsoft Visual Studio 20xx x64 tools.

  4. Now, run the setup via python setup.py install or pip install pkg-name

  5. Hope and cross your fingers that the planets are aligned correctly for VC++ to cooperate.


回答 4

这是怎么回事?Python模块可以用C或C ++编写(通常是为了提高速度)。如果尝试使用Pip(或setup.py)安装这样的软件包,则必须从源代码编译该C / C ++。开箱即用,Pip会大胆假设您已安装了Microsoft Visual C ++编译器。如果没有它,您将看到此错误消息“错误:无法找到vcvarsall.bat”。

规定的解决方案是安装C / C ++编译器,Microsoft Visual C ++或MinGW(一个开源项目)。但是,安装和配置任何一个都非常困难。(编辑2014:Microsoft已发布了用于Python 2.7 的特殊C ++编译器

最简单的解决方案是将Christoph Gohlke的Windows安装程序(.msi)用于流行的Python软件包。他为Python 2.x和3.x,32位和64位构建安装程序。您可以从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载它们


如果您也认为“错误:无法找到vcvarsall.bat”是一个含糊不清和无用的消息,请在http://bugs.python.org/issue2943上对该错误进行评论,以更有用和更用户化的方式替换它。友好的消息。

为了进行比较,Ruby附带了软件包管理器Gem,并提供了一个准官方的C / C ++编译器DevKit。如果您尝试安装不带该软件包的软件包,则会看到此有用的友好有用消息:

请更新您的PATH以包含构建工具,或从http://rubyinstaller.org/downloads下载DevKit 并按照http://github.com/oneclick/rubyinstaller/wiki/Development-Kit上的说明进行操作

您可以在https://stackoverflow.com/a/13445719/284795上阅读有关Python打包的更长篇文章

What’s going on? Python modules can be part written in C or C++ (typically for speed). If you try to install such a package with Pip (or setup.py), it has to compile that C/C++ from source. Out the box, Pip will brazenly assume you the compiler Microsoft Visual C++ installed. If you don’t have it, you’ll see this cryptic error message “Error: Unable to find vcvarsall.bat”.

The prescribed solution is to install a C/C++ compiler, either Microsoft Visual C++, or MinGW (an open-source project). However, installing and configuring either is prohibitively difficult. (Edit 2014: Microsoft have published a special C++ compiler for Python 2.7)

The easiest solution is to use Christoph Gohlke’s Windows installers (.msi) for popular Python packages. He builds installers for Python 2.x and 3.x, 32 bit and 64 bit. You can download them from http://www.lfd.uci.edu/~gohlke/pythonlibs/


If you too think “Error: Unable to find vcvarsall.bat” is a ludicrously cryptic and unhelpful message, then please comment on the bug at http://bugs.python.org/issue2943 to replace it with a more helpful and user-friendly message.

For comparison, Ruby ships with a package manager Gem and offers a quasi-official C/C++ compiler, DevKit. If you try to install a package without it, you see this helpful friendly useful message:

Please update your PATH to include build tools or download the DevKit from http://rubyinstaller.org/downloads and follow the instructions at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit

You can read a longer rant about Python packaging at https://stackoverflow.com/a/13445719/284795


回答 5

您需要安装与用于构建Python的编译器兼容的Microsoft编译器。这意味着您需要Visual C ++ 2008(或更高版本,需要进行一些调整)。

微软现在提供一个捆绑的编译器和头能够编译Python扩展,在好记的网址:

适用于Python 2.7的Microsoft Visual C ++编译器

http://aka.ms/vcpython27

这是一个相对较小的包装;下载85MB,无需管理员权限即可安装,无需重新启动。名称有点误导,该编译器适用于最初使用Visual C ++ 2008编译的任何Python版本,而不仅仅是Python 2.7。

如果您启动Python交互式提示或print sys.version,请查找MSC版本字符串;否则,请执行以下操作:如果是这样,MSC v.1500您可以使用此工具。

原始公告到distutils列表

微软已经发布了适用于Python 2.7的编译器软件包,以使人们可以更轻松地在Windows上构建和分发C扩展模块。可从以下网站获得用于Python 2.7的Microsoft Visual C ++编译器(aka VC9):http : //aka.ms/vcpython27

该软件包包含为32位和64位Python 2.7构建C扩展模块所需的所有工具和头文件(请注意,某些扩展模块需要第三方的依赖项,例如OpenSSL或libxml2,但不包括在内)。还支持使用Visual C ++ 2008构建的其他Python版本,因此“ Python 2.7”仅是广告-可以在2.6和3.2上正常工作。

请注意,您需要安装setuptools6.0或更高版本(在下载页面的系统要求中列出)。您正在安装的项目必须使用setuptools.setup(),而不是,distutils否则自动检测将不起作用。

Microsoft已声明他们希望保持URL稳定,以便自动脚本可以轻松引用它。

You’ll need to install a Microsoft compiler, compatible with the compiler used to build Python. This means you need Visual C++ 2008 (or newer, with some tweaking).

Microsoft now supplies a bundled compiler and headers just to be able to compile Python extensions, at the memorable URL:

Microsoft Visual C++ Compiler for Python 2.7

http://aka.ms/vcpython27

This is a relatively small package; 85MB to download, installable without admin privileges, no reboot required. The name is a little misleading, the compiler will work for any Python version originally compiled with Visual C++ 2008, not just Python 2.7.

If you start a Python interactive prompt or print sys.version, look for the MSC version string; if it is MSC v.1500 you can use this tool.

From the original announcement to the distutils list:

Microsoft has released a compiler package for Python 2.7 to make it easier for people to build and distribute their C extension modules on Windows. The Microsoft Visual C++ Compiler for Python 2.7 (a.k.a. VC9) is available from: http://aka.ms/vcpython27

This package contains all the tools and headers required to build C extension modules for Python 2.7 32-bit and 64-bit (note that some extension modules require 3rd party dependencies such as OpenSSL or libxml2 that are not included). Other versions of Python built with Visual C++ 2008 are also supported, so “Python 2.7” is just advertising – it’ll work fine with 2.6 and 3.2.

Note that you need to have setuptools 6.0 or newer installed (listed in the system requirements on the download page). The project you are installing must use setuptools.setup(), not distutils or the auto-detection won’t work.

Microsoft has stated that they want to keep the URL stable, so that automated scripts can reference it easily.


回答 6

我只是遇到了同样的问题,所以我在这里讲述我的故事,希望它可以帮助遇到同样问题的其他人,并为他们节省几个小时的时间:

我在Windows 7盒子中有mingw(g ++(GCC)4.6.1)和python 2.7.3,我正在尝试安装PyCrypto。

运行setup.py install时,所有错误均始于此错误:

error: Unable to find vcvarsall.bat

通过将mingw指定为选择的编译器,可以轻松地在搜索错误之后解决此问题:

setup.py install build --compiler=mingw32

问题是然后我得到了另一个错误:

configure: error: cannot run C compiled programs.

事实证明,我的防病毒软件阻止了新编译的.exe的执行。我只是禁用了防病毒“居民防护罩”,然后转到下一个错误:

cc1.exe: error: unrecognized command line option '-mno-cygwin' 
error: command 'gcc' failed with exit status 1

解决了它:“要么安装稍旧版本的MinGW,要么在您的Python目录中编辑distutils \ cygwinccompiler.py以删除-mno-cygwin的所有实例。” (从这里开始

现在,我终于可以开始工作了。

I just had this same problem, so I’ll tell my story here hoping it helps someone else with the same issues and save them the couple of hours I just spent:

I have mingw (g++ (GCC) 4.6.1) and python 2.7.3 in a windows 7 box and I’m trying to install PyCrypto.

It all started with this error when running setup.py install:

error: Unable to find vcvarsall.bat

Easily solved after googling the error by specifying mingw as the compiler of choice:

setup.py install build --compiler=mingw32

The problem is that then I got a different error:

configure: error: cannot run C compiled programs.

It turns out that my anti-virus was blocking the execution of a freshly compiled .exe. I just disabled the anti-virus “resident shield” and went to the next error:

cc1.exe: error: unrecognized command line option '-mno-cygwin' 
error: command 'gcc' failed with exit status 1

This solved it: “Either install a slightly older version of MinGW, or edit distutils\cygwinccompiler.py in your Python directory to remove all instances of -mno-cygwin.” (from here)

Now, I can finally start working.


回答 7

看起来它正在寻找VC编译器,因此您可以尝试使用来提及编译器类型-c mingw32,因为您拥有msys

python setup.py install -c mingw32

Looks like its looking for VC compilers, so you could try to mention compiler type with -c mingw32, since you have msys

python setup.py install -c mingw32

回答 8

我有python 2.73和Windows 7。对我有用的解决方案是:

  1. 新增的mingw32的bin目录到环境变量:追加PATHC:\programs\mingw\bin;
  2. 创建的distutils.cfg位于C:\Python27\Lib\distutils\distutils.cfg

    [build]
    compiler=mingw32

要处理MinGW不再识别-mno-cygwin标志的情况,请删除C:\ Python27 \ Lib \ distutils \ cygwincompiler.py第322行至326行中的标志,因此如下所示:

  self.set_executables(compiler='gcc -O -Wall',
                         compiler_so='gcc -mdll -O -Wall',
                         compiler_cxx='g++ -O -Wall',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

I have python 2.73 and windows 7 .The solution that worked for me was:

  1. Added mingw32’s bin directory to environment variable: append PATH with C:\programs\mingw\bin;
  2. Created distutils.cfg located at C:\Python27\Lib\distutils\distutils.cfg containing:

    [build]
    compiler=mingw32
    

To deal with MinGW not recognizing the -mno-cygwin flag anymore, remove the flag in C:\Python27\Lib\distutils\cygwincompiler.py line 322 to 326, so it looks like this:

  self.set_executables(compiler='gcc -O -Wall',
                         compiler_so='gcc -mdll -O -Wall',
                         compiler_cxx='g++ -O -Wall',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

回答 9

查看setup.py您要安装的软件包的文件。如果是较旧的软件包,则可能是导入distutils.core.setup()而不是setuptools.setup()

我在2015年遇到了以下这些因素:

  1. 来自http://aka.ms/vcpython27的适用于Python 2.7的Microsoft Visual C ++编译器

  2. 使用较旧的软件包 distutils.core.setup()

  3. 尝试做python setup.py build而不是使用pip

如果您使用的是最新版本的pip,则它将强制(monkeypatch)软件包使用setuptools,即使其setup.py对distutils的调用也是如此。但是,如果您不使用pip而是在做python setup.py build,则构建过程将使用distutils.core.setup(),而后者不知道编译器的安装位置。


步骤1:打开适当的Visual C ++ 2008命令提示符

打开“开始”菜单或“开始”屏幕,然后搜索“ Visual C ++ 2008 32位命令提示符”(如果您的Python是32位)或“ Visual C ++ 2008 64位命令提示符”(如果您的Python是64位) 。运行。命令提示符在标题栏中应显示Visual C ++ 2008…。

步骤2:设定环境变数

在刚打开的命令提示符中设置这些环境变量。

SET DISTUTILS_USE_SDK=1
SET MSSdk=1

参考http://bugs.python.org/issue23246

步骤3:建立并安装

cd到要构建并运行的包python setup.py build,然后python setup.py install。如果要安装到virtualenv,请在构建之前将其激活。

Look in the setup.py file of the package you are trying to install. If it is an older package it may be importing distutils.core.setup() rather than setuptools.setup().

I ran in to this (in 2015) with a combination of these factors:

  1. The Microsoft Visual C++ Compiler for Python 2.7 from http://aka.ms/vcpython27

  2. An older package that uses distutils.core.setup()

  3. Trying to do python setup.py build rather than using pip.

If you use a recent version of pip, it will force (monkeypatch) the package to use setuptools, even if its setup.py calls for distutils. However, if you are not using pip, and instead are just doing python setup.py build, the build process will use distutils.core.setup(), which does not know about the compiler install location.


Solution

Step 1: Open the appropriate Visual C++ 2008 Command Prompt

Open the Start menu or Start screen, and search for “Visual C++ 2008 32-bit Command Prompt” (if your python is 32-bit) or “Visual C++ 2008 64-bit Command Prompt” (if your python is 64-bit). Run it. The command prompt should say Visual C++ 2008 … in the title bar.

Step 2: Set environment variables

Set these environment variables in the command prompt you just opened.

SET DISTUTILS_USE_SDK=1
SET MSSdk=1

Reference http://bugs.python.org/issue23246

Step 3: Build and install

cd to the package you want to build, and run python setup.py build, then python setup.py install. If you want to install in to a virtualenv, activate it before you build.


回答 10

也许有人会感兴趣,以下对py2exe软件包有用。(我有Windows 7 64位和便携式python 2.7,带有适用于Windows 7和.NET Framework 4的Windows SDK的Visual Studio 2005 Express)

set VS90COMNTOOLS=%VS80COMNTOOLS%

然后:

python.exe setup.py install

Maybe somebody can be interested, the following worked for me for the py2exe package. (I have windows 7 64 bit and portable python 2.7, Visual Studio 2005 Express with Windows SDK for Windows 7 and .NET Framework 4)

set VS90COMNTOOLS=%VS80COMNTOOLS%

then:

python.exe setup.py install

回答 11

我花了将近2天的时间弄清楚如何在python 3.4 64位版本中解决此问题:Python 3.4.3(v3.4.3:9b73f1c3e601,Feb 24 2015,22:44:40)[MSC v.1600 64位(AMD64 )]在win32上

困难的解决方案1 ​​:(在阅读本文之前,请先阅读下面的解决方案2)最后,这对我有帮助:

  1. 安装Visual C ++ 2010 Express
  2. 为Windows 7安装Microsoft Windows SDK v7.1
  3. 手动创建文件vcvars64.batC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64其中包含CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64或其他路径,具体取决于安装位置
  4. (这似乎是可选的)针对Windows SDK 7.1安装Microsoft Visual Studio 2010 Service Pack 1以及Microsoft Visual C ++ 2010 Service Pack 1编译器更新
  5. 之后,我尝试pip install numpy但收到以下错误:

    File "numpy\core\setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program

    我改mfinfoNoneC:\Python34\Lib\distutils\msvc9compiler.py每本https://stackoverflow.com/a/23099820/4383472

  6. 最终在pip install numpy命令后,我的avast防病毒软件试图干扰安装过程,但我很快将其禁用

花费了很长时间-numpy编译了几分钟,我什至以为出现了错误,但最终一切都OK。

解决方案2,简单:( 我知道这种方法已经在高度投票的答案中提到过,但是由于它确实更容易,所以让我重复一下)经过所有这些工作之后,我了解到对我来说最好的方法就是使用将来可从http://www.lfd.uci.edu/~gohlke/pythonlibs/预编译二进制文件。我极少需要此网站不包含的某些软件包(或软件包的版本)。这种方式的安装过程也更快。例如,安装numpy

  1. numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl从该站点下载(如果您具有Python 3.4 64位)
  2. 在命令提示符或Powershell中使用pip安装pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl(或文件的完整路径,具体取决于打开命令提示符的方式)

I spent almost 2 days figuring out how to fix this problem in my python 3.4 64 bit version: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32

Solution 1, hard: (before reading this, read first Solution 2 below) Finally, this is what helped me:

  1. install Visual C++ 2010 Express
  2. install Microsoft Windows SDK v7.1 for Windows 7
  3. create manually file vcvars64.bat in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 which contains CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 or other path depending on where you have yours installed
  4. (this seems to be optional) install Microsoft Visual Studio 2010 Service Pack 1 together with Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1
  5. after that I tried to pip install numpy but received the following error:

    File "numpy\core\setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program
    

    I changed mfinfo to None in C:\Python34\Lib\distutils\msvc9compiler.py per this https://stackoverflow.com/a/23099820/4383472

  6. finally after pip install numpy command my avast antivirus tried to interfere into the installation process, but i quickly disabled it

It took very long – several minutes for numpy to compile, I even thought that there was an error, but finally everything was ok.

Solution 2, easy: (I know this approach has already been mentioned in a highly voted answer, but let me repeat since it really is easier) After going through all of this work I understood that the best way for me is just to use already precompiled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ in future. There is very small chance that I will ever need some package (or a version of a package) which this site doesn’t contain. The installation process is also much quicker this way. For example, to install numpy:

  1. donwload numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl (if you have Python 3.4 64-bit) from that site
  2. in command prompt or powershell install it with pip pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl (or full path to the file depending how command prompt is opened)

回答 12

我想在Windows 10上的python 2.7下运行pysph并找不到vcvarsall.bat(来自distutils)

我的解决方案如下:

为Python 2.7安装Microsoft Visual C ++(建议@Michael)

在Windows 10上,它已安装到(我的用户名是Andreas):

C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

设置环境变量VS90COMNTOOLS为Visual C ++ for Python 2.7的安装路径(请参见上面的路径)。

如果仍然无法使用,请在模块中进行修改

C:/Python27/lib/distutils

文件msvc9compiler.py。在其中找到功能find_vcvarsall并进行以下修改。

替换行:

productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")

productdir = os.path.join(toolsdir)

在我的情况下,这就是vcvarsall.bat所在的位置(请检查vcvarsall.bat在您的安装位置中)。

I wanted to run pysph on Windows 10 under Python 2.7 and got vcvarsall.bat was not found (from distutils)

My solution was the following:

Install Microsoft Visual C++ for Python 2.7 (like @Michael suggested)

On Windows 10 it was installed into (my username is Andreas):

C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

Set environment variable VS90COMNTOOLS to the installation path of Visual C++ for Python 2.7 (see above path).

If it still doesn’t work, then modifiy in the module

C:/Python27/lib/distutils

the file msvc9compiler.py. Find in it the function find_vcvarsall and do following modification.

Replace the line:

productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")

with

productdir = os.path.join(toolsdir)

This is where vcvarsall.bat resides in my case (check, where vcvarsall.bat is in your installation).


回答 13

当我尝试在python 3.5上安装numpy库时遇到此问题。解决的办法是安装VS2015。我有VS2008、2012、2013,其中没有一个与python 3.5兼容。显然,较新版本的python依赖于较新版本的VS。

还要确保Visual Studio已安装C ++通用工具。

I encountered this issue when I tried to install numpy library on my python 3.5. The solution is to install VS2015. I had VS2008, 2012, 2013, none of which is compatible with python 3.5. Apparently newer version of python has dependency on newer versions of VS.

Also make sure C++ Common Tools are installed with Visual Studio.


回答 14

我尝试了上述所有答案,但发现它们都不起作用,这可能是我使用Windows 8并安装了Visual Studio2012。在这种情况下,这就是您要做的。

vcvarsall.bat文件位于此处: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC

只需选择文件,然后将其复制。

然后转到此目录: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools

并粘贴文件。然后,一切都会好起来。

I tried all the above answers, and found all of them not to work, this was perhaps I was using Windows 8 and had installed Visual Studio 2012. In this case, this is what you do.

The vcvarsall.bat file is located here: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC

Simply select the file, and copy it.

Then go to this directory: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools

and paste the file. And then, all should be well.


回答 15

您可以从http://go.microsoft.com/?linkid=7729279下载免费的Visual C ++ 2008 Express Edition ,它将在安装过程中设置VS90COMNTOOLS环境变量,并因此使用兼容的编译器进行构建。

正如@PiotrDobrogost在评论中提到的那样,他对另一个问题的回答详细介绍了为什么要使用Visual C ++ 2008构建正确的东西,但是随着Windows的Python构建转移到更新版本的Visual Studio,这种情况可能会改变:构建lxml适用于Windows上的Python 2.7

You can download the free Visual C++ 2008 Express Edition from http://go.microsoft.com/?linkid=7729279, which will set the VS90COMNTOOLS environment variable during installation and therefore build with a compatible compiler.

As @PiotrDobrogost mentioned in a comment, his answer to this other question goes into details about why Visual C++ 2008 is the right thing to build with, but this can change as the Windows build of Python moves to newer versions of Visual Studio: Building lxml for Python 2.7 on Windows


回答 16

在Windows 7 x64上使用Python 3.4.1遇到了这个问题,不幸的是,我需要的软件包没有合适的exe或wheel可供使用。该系统需要一些“解决方法”,下面对此进行了详细说明(底部是TLDR)。

使用上面Jaxrtech的答案中的信息,我确定我需要Visual Studio C ++ 2010(sys.version返回MSC v.1600),因此我从他的答案中的链接http://go.microsoft安装了Visual C ++ 2010 Express。.com /?linkid = 9709949。我安装了所有带有更新的内容,但是正如您在下面看到的那样,这是一个错误。此时仅应安装Express的原始版本(不更新任何内容)。

vcvarsall.bat现在存在,但是在安装软件包时出现了新错误query_vcvarsall raise ValueError(str(list(result.keys())))ValueError: [u'path']。还有其他与此错误有关的stackoverflow问题,例如为Python 2.7构建/安装C模块时出现的错误

根据该答案,我确定2010 Express仅安装32位编译器。要获取64位(和其他)编译器,您需要安装Windows 7.1 SDK。请参阅http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx

但是,这不会为我安装,安装程序返回了错误installation failed with return code 5100。我在以下链接中找到了解决方案:http : //support.microsoft.com/kb/2717426。简而言之,如果安装了x86和x64 Microsoft Visual C ++ 2010 Redistributable的较新版本,它们将与SDK安装程序中的版本冲突,因此需要先进行卸载。

然后安装了SDK,但是我注意到vcvars64.bat仍然不存在C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin,也没有其子文件夹。vcvarsall.bat运行vcvars64批处理文件,因此如果没有该文件,python软件包仍将无法安装(我忘记了此时显示的错误)。

然后 ,我在这里找到了一些说明:http : //www.cryptohaze.com/wiki/index.php/Windows_7_Build_Setup#Download_VS_2010_and_Windows_SDK_7.1按照说明,我已经安装了Express和7.1 SDK,因此安装了SDK 7.1 SP1,并做了缺少头文件修复。然后,我使用content手动创建vcvars64.bat CALL setenv /x64。我将所有这些说明粘贴在这里,以免丢失。

步骤1是下载Visual Studio Express 2010。

http://www.microsoft.com/visualstudio/zh-cn/products/2010-editions/express 是一个不错的起点。下载安装程序,然后运行它(vc_web.exe)。您不需要SQL 2008的其他下载。

对于64位编译器,您还需要Windows SDK(当前为7.1)-除非您只想进行32位构建,否则将不完全支持…

http://www.microsoft.com/zh-cn/download/details.aspx?id=8279是下载此文件的好起点-下载后,您将要运行winsdk_web.exe!

这里的默认安装就可以了。

最后,下载并安装Windows SDK 7.1 SP1更新:http : //www.microsoft.com/zh-cn/download/details.aspx?id=4422

并且,要修复缺少的头文件,VS2010 SP1。 http://www.microsoft.com/downloads/zh-CN/confirmation.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5

而且,该死的,为VS2010 Express修复丢失的批处理文件。这真是荒唐可笑。

在C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64中,使用以下命令创建“ vcvars64.bat”(您将需要以管理员身份运行):

呼叫setenv / x64

我的python软件包仍然没有安装(无法回忆起错误)。然后,我找到了一些使用特殊的SDK 7.1命令提示符的说明(在下面复制),请参阅:https : //mail.python.org/pipermail/distutils-sig/2012-February/018300.html

没关系,这个问题。此处有人在菜单上注意到此项目:开始->所有程序-> Microsoft Windows SDK v7.1-> Windows SDK 7.1命令提示符

这将运行一个批处理作业,该作业似乎为编译器设置了工作环境。在该提示下,您可以键入“ setup.py build”或“ setup.py install”。

我按照指示打开了Windows SDK 7.1命令提示符,并使用它在python软件包上运行easy_install。最后,成功!


TLDR ;

  1. 安装Visual Studio Express 2010(最好没有更新的可再发行文件或SQL Server)。
  2. 安装Windows 7.1 SDK
  3. Instal SDK 7.1 SP1更新和VS2010 SP1标头文件修复(可能不需要此步骤)。
  4. 手动创建C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat内容CALL setenv /x64
  5. 开始->所有程序-> Microsoft Windows SDK v7.1-> Windows SDK 7.1命令提示符以打开特殊的x64命令提示符,然后可以将其与python / easy_install / pip / etc(包括virtual_envs中的命令)一起使用。

I had this problem using Python 3.4.1 on Windows 7 x64, and unfortunately the packages I needed didn’t have suitable exe or wheels that I could use. This system requires a few ‘workarounds’, which are detailed below (and TLDR at bottom).

Using the info in Jaxrtech’s answer above, I determined I needed Visual Studio C++ 2010 (sys.version return MSC v.1600), so I installed Visual C++ 2010 Express from the link in his answer, which is http://go.microsoft.com/?linkid=9709949. I installed everything with updates, but as you can read below, this was a mistake. Only the original version of Express should be installed at this time (no updated anything).

vcvarsall.bat was now present, but there was a new error when installing the package, query_vcvarsall raise ValueError(str(list(result.keys())))ValueError: [u'path']. There are other stackoverflow questions with this error, such as Errors while building/installing C module for Python 2.7

I determined from that answer that 2010 Express only installs 32-bit compilers. To get 64-bit (and other) compilers, you need to install Windows 7.1 SDK. See http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx

This would not install for me though, and the installer returned the error installation failed with return code 5100. I found the solution at the following link: http://support.microsoft.com/kb/2717426. In short, if newer versions of x86 and x64 Microsoft Visual C++ 2010 Redistributable’s are installed, they conflict with the ones in SDK installer, and need uninstalling first.

The SDK then installed, but I noticed vcvars64.bat still did not exist in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin, nor its subfolders. vcvarsall.bat runs the vcvars64 batch file, so without it, the python package still wouldn’t install (I forgot the error that was shown at this time).

I then found some instructions here: http://www.cryptohaze.com/wiki/index.php/Windows_7_Build_Setup#Download_VS_2010_and_Windows_SDK_7.1 Following the instructions, I had already installed Express and 7.1 SDK, so installed SDK 7.1 SP1, and did the missing header file fix. I then manually created vcvars64.bat with the content CALL setenv /x64. I will paste all those instructions here, so they don’t get lost.

Step 1 is to download Visual Studio Express 2010.

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express is a good place to start. Download the installer, and run it (vc_web.exe). You don’t need the SQL 2008 additional download.

You’ll also need the Windows SDK (currently 7.1) for the 64-bit compilers – unless you want to do 32-bit only builds, which are not fully supported…

http://www.microsoft.com/en-us/download/details.aspx?id=8279 is a good starting point to download this – you’ll want to run winsdk_web.exe when downloaded!

The default install here is just fine.

Finally, download and install the Windows SDK 7.1 SP1 update: http://www.microsoft.com/en-us/download/details.aspx?id=4422

And, to fix missing header file, VS2010 SP1. http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5

And, bloody hell, fix the missing batch file for VS2010 Express. This is getting downright absurd.

In C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64, create “vcvars64.bat” with the following (you will need to be running as administrator):

CALL setenv /x64

My python package still did not install (can’t recall error). I then found some instructions (copied below) to use the special SDK 7.1 Command Prompt, see: https://mail.python.org/pipermail/distutils-sig/2012-February/018300.html

Never mind this question. Somebody here noticed this item on the menu: Start->All Programs->Microsoft Windows SDK v7.1 ->Windows SDK 7.1 Command Prompt

This runs a batch job that appears to set up a working environment for the compiler. From that prompt, you can type “setup.py build” or “setup.py install”.

I opened the Windows SDK 7.1 Command Prompt as instructed, and used it to run easy_install on the python package. And at last, success!


TLDR;

  1. Install Visual Studio Express 2010 (preferably without updated redistributables or SQL server).
  2. Install Windows 7.1 SDK
  3. Instal SDK 7.1 SP1 update, and VS2010 SP1 header file fix (this step may not be required).
  4. Manually create C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat with content CALL setenv /x64
  5. Start->All Programs->Microsoft Windows SDK v7.1 ->Windows SDK 7.1 Command Prompt to open special x64 command prompt, which can then be used with python/easy_install/pip/etc (including those in virtual_envs).

回答 17

下面的步骤为我解决了这个问题,我试图用cython扩展创建安装程序。

  1. 安装适用于Python 2.7的Microsoft Visual C ++编译器
  2. 默认安装位置为@ C:\ Users \ PC-user \ AppData \ Local \ Programs \ Common \ Microsoft \ Visual C ++ for Python。这实际上可以解决此问题,请在继续操作之前进行一次测试。
  3. 如果失败,请检查VC ++中python vcvarsall.bat文件的位置。
  4. 在记事本中打开distutils软件包的msvc9compiler.py文件。
  5. 在我的框中,这是该文件中的@ C:\ Anaconda2 \ Lib \ distutils \ msvc9compiler.py find_vcvarsall函数,通过打印出版本参数来确定VC的版本。对于Python 2.7,可能是9.0
  6. 现在创建一个环境变量VS90COMNTOOLS,指向C:\ Users \ PC-user \ AppData \ Local \ Programs \ Common \ Microsoft \ Visual C ++ for Python \ 9.0 \ VC \ bin
  7. 由于某种原因,distutils期望vcvarsall.bat文件位于VC目录中,但是python工具的VC ++在9.0的根目录中有此文件。要解决此问题,请从path.join中删除“ VC”(大约在247行附近)

    #productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.join(toolsdir, os.pardir, os.pardir)

上面的步骤为我解决了这个问题。

Below steps fixed this issue for me, I was trying to create setup with cython extension.

  1. Install Microsoft Visual C++ Compiler for Python 2.7
  2. The default install location would be @ C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python This might actually fix the issue, test once before proceeding.
  3. If it fails, Check where in VC++ for python vcvarsall.bat file is located
  4. Open the msvc9compiler.py file of distutils package in notepad.
  5. In my box this was @ C:\Anaconda2\Lib\distutils\msvc9compiler.py find_vcvarsall function in this file, determine the version of VC by printing out version argument. For Python 2.7 it’s likely to be 9.0
  6. Now create an environment variable VS90COMNTOOLS, Pointing to C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\bin
  7. For some reason distutils expects the vcvarsall.bat file to be within VC dir, but VC++ for python tools has it in the root of 9.0 To fix this, remove “VC” from the path.join (roughly around line 247)

    #productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.join(toolsdir, os.pardir, os.pardir)

The above steps fixed the issue for me.


回答 18

我尝试了许多解决方案,但只有一种对我有用,即安装Microsoft Visual Studio 2008 Express C ++。

我用用C编写的Python 2.7模块(yEnc,MS VS还有其他问题)遇到了这个问题。请注意,Python 2.7是使用MS VS 2008版本而非2010构建的!

尽管它是免费的,但由于MS正在推广VS 2010,因此很难找到它。但是,MSDN官方非常直接的链接仍在起作用:请访问https://stackoverflow.com/a/15319069/2227298以获取下载链接。

I tried many solutions but only one worked for me, the install of Microsoft Visual Studio 2008 Express C++.

I got this issue with a Python 2.7 module written in C (yEnc, which has other issues with MS VS). Note that Python 2.7 is built with MS VS 2008 version, not 2010!

Despite the fact it’s free, it is quite hard to find since MS is promoting VS 2010. Still, the MSDN official very direct links are still working: check https://stackoverflow.com/a/15319069/2227298 for download links.


回答 19

如果您已安装mingw

pip install --global-option build_ext --global-option --compiler=mingw32 packagename

起作用,迫使pip使用mingw编译器而不是Microsoft的编译器进行构建。有关详细信息,请参见https://github.com/pypa/pip/issues/18(最新文章)。

If you have mingw installed

pip install --global-option build_ext --global-option --compiler=mingw32 packagename

works, forcing pip to build using the mingw compiler instead of Microsoft’s. See here https://github.com/pypa/pip/issues/18 for details (last post).


回答 20

http://www.microsoft.com/zh-cn/download/details.aspx?id=44266上的 Python 2.7版Microsoft Visual C ++编译器不是解决方案吗?

Is Microsoft Visual C++ Compiler for Python 2.7 at http://www.microsoft.com/en-us/download/details.aspx?id=44266 not a solution?


回答 21

在2016年解决此问题的最简单方法是先安装Chocolatey,然后再安装该 vcpython27软件包。打开Powershell:

> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install python2 -y
> choco install vcpython27 -y

The easiest way to solve this in 2016 is to install Chocolatey and then the vcpython27 package. Open Powershell:

> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install python2 -y
> choco install vcpython27 -y

回答 22

我不知道这是否是为时已晚,但我发现微软的Visual C ++编译器为Python 2.7读取

如果需要此编译器包,您将收到的典型错误消息是找不到vcvarsall.bat

希望这可以帮助!

I don’t know if it is too late, but I found Microsoft Visual C++ Compiler for Python 2.7 which reads

The typical error message you will receive if you need this compiler package is Unable to find vcvarsall.bat

Hope this helps!


回答 23

我遇到了同样的问题,目前已经解决了。

“ Google”告诉我,我需要安装“ Python 2.7的Microsoft Visual C ++编译器”。我不仅安装了该工具,还安装了Visual C ++ 2008 Reditributable,但这并没有帮助。然后,我尝试安装Visual C ++ 2008 Express Edition。问题已经解决了!

只需尝试安装Visual C ++ 2008 Express Edition!

I got the same problem and have solved it at the moment.

“Google” told me that I need to install “Microsoft Visual C++ Compiler for Python 2.7”. I install not only the tool, but also Visual C++ 2008 Reditributable, but it didn’t help. I then tried to install Visual C++ 2008 Express Edition. And the problem has gone!

Just try to install Visual C++ 2008 Express Edition!


回答 24

调用import setuptools将Monkey补丁distutils强制与Visual Studio兼容。vcvars32.bat手动调用将设置虚拟环境,并防止编译器引发其他常见错误。对于VS 2017,文件位于

“ C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Community \ VC \ Auxiliary \ Build \ vcvars32.bat”

这是我用来快速将.pyx文件编译为.pyd的安装脚本:(注意:它使用第三方模块 send2trash

# cython_setup.py
import sys, os, time, platform, subprocess
from setuptools import setup, find_packages
from Cython.Build import cythonize
from traceback import format_exc

# USAGE:
#
#   from cython_setup import run
#   run(pyx_path)

# vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"

# NOTE: to use visual studio 2017 you must have setuptools version 34+
vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars32.bat"


def _build_ext():
    try:
        pyx_path = sys.argv.pop(-1)
        pyx_path = os.path.abspath(pyx_path)
        if not os.path.exists(pyx_path):
            raise FileNotFoundError(f"{pyx_path} does not exist")
        project_name = sys.argv.pop(-1)
        os.chdir(os.path.abspath(os.path.dirname(pyx_path)))

        print("cwd: %s" % os.getcwd())
        print(os.path.abspath("build"))
        setup(
            name=project_name,
            # cmdclass = {'build_ext': build_ext},
            packages=find_packages(),
            # ext_modules=cythonize(extensions)
            ext_modules=cythonize(pyx_path,
                                  compiler_directives={'language_level': 3, 'infer_types': True, 'binding': False},
                                  annotate=True),
            # include_dirs = [numpy.get_include()]
            build_dir=os.path.abspath("build")
        )
    except:
        input(format_exc())


def retry(func):
    def wrapper(*args, **kw):
        tries = 0
        while True:
            try:
                return func(*args, **kw)
            except Exception:
                tries += 1
                if tries > 4:
                    raise
                time.sleep(0.4)

    return wrapper


@retry
def cleanup(pyx_path):
    from send2trash import send2trash
    c_file = os.path.splitext(pyx_path)[0] + ".c"
    if os.path.exists(c_file):
        os.remove(c_file)

    if os.path.exists("build"):
        send2trash("build")


def move_pyd_files(pyx_path):
    pyx_dir = os.path.dirname(pyx_path)
    build_dir = os.path.join(pyx_dir, "build")
    if not os.path.exists(build_dir):
        raise RuntimeError(f"build_dir {build_dir} did not exist....")
    found_pyd = False
    for top, dirs, nondirs in os.walk(build_dir):
        for name in nondirs:
            if name.lower().endswith(".pyd") or name.lower().endswith(".so"):
                found_pyd = True
                old_path = os.path.join(top, name)
                new_path = os.path.join(pyx_dir, name)
                if os.path.exists(new_path):
                    print(f"removing {new_path}")
                    os.remove(new_path)
                print(f"file created at {new_path}")
                os.rename(old_path, new_path)
    if not found_pyd:
        raise RuntimeError("Never found .pyd file to move")

def run(pyx_path):
    """
    :param pyx_path:
    :type pyx_path:
    :return: this function creates the batch file, which in turn calls this module, which calls cythonize, once done
    the batch script deletes itself... I'm sure theres a less convoluted way of doing this, but it works
    :rtype:
    """
    try:
        project_name = os.path.splitext(os.path.basename(pyx_path))[0]
        run_script(project_name, os.path.abspath(pyx_path))
    except:
        input(format_exc())


def run_script(project_name, pyx_path):
    dirname = os.path.dirname(pyx_path)
    # ------------------------------
    os.chdir(dirname)
    if os.path.exists(vcvars):
        #  raise RuntimeError(
        # f"Could not find vcvars32.bat at {vcvars}\nis Visual Studio Installed?\nIs setuptools version > 34?")
        subprocess.check_call(f'call "{vcvars}"', shell=True)

    cmd = "python" if platform.system() == "Windows" else "python3"
    subprocess.check_call(f'{cmd} "{__file__}" build_ext "{project_name}" "{pyx_path}"', shell=True)
    move_pyd_files(pyx_path)
    cleanup(pyx_path)


if len(sys.argv) > 2:
    _build_ext()

calling import setuptools will monkey patch distutils to force compatibility with Visual Studio. Calling vcvars32.bat manually will setup the virtual environment and prevent other common errors the compiler will throw. For VS 2017 the file is located at

“C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat”

Here is the setup script I use to quickly compile .pyx files to .pyd: (Note: it uses the 3rd party module send2trash

# cython_setup.py
import sys, os, time, platform, subprocess
from setuptools import setup, find_packages
from Cython.Build import cythonize
from traceback import format_exc

# USAGE:
#
#   from cython_setup import run
#   run(pyx_path)

# vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"

# NOTE: to use visual studio 2017 you must have setuptools version 34+
vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars32.bat"


def _build_ext():
    try:
        pyx_path = sys.argv.pop(-1)
        pyx_path = os.path.abspath(pyx_path)
        if not os.path.exists(pyx_path):
            raise FileNotFoundError(f"{pyx_path} does not exist")
        project_name = sys.argv.pop(-1)
        os.chdir(os.path.abspath(os.path.dirname(pyx_path)))

        print("cwd: %s" % os.getcwd())
        print(os.path.abspath("build"))
        setup(
            name=project_name,
            # cmdclass = {'build_ext': build_ext},
            packages=find_packages(),
            # ext_modules=cythonize(extensions)
            ext_modules=cythonize(pyx_path,
                                  compiler_directives={'language_level': 3, 'infer_types': True, 'binding': False},
                                  annotate=True),
            # include_dirs = [numpy.get_include()]
            build_dir=os.path.abspath("build")
        )
    except:
        input(format_exc())


def retry(func):
    def wrapper(*args, **kw):
        tries = 0
        while True:
            try:
                return func(*args, **kw)
            except Exception:
                tries += 1
                if tries > 4:
                    raise
                time.sleep(0.4)

    return wrapper


@retry
def cleanup(pyx_path):
    from send2trash import send2trash
    c_file = os.path.splitext(pyx_path)[0] + ".c"
    if os.path.exists(c_file):
        os.remove(c_file)

    if os.path.exists("build"):
        send2trash("build")


def move_pyd_files(pyx_path):
    pyx_dir = os.path.dirname(pyx_path)
    build_dir = os.path.join(pyx_dir, "build")
    if not os.path.exists(build_dir):
        raise RuntimeError(f"build_dir {build_dir} did not exist....")
    found_pyd = False
    for top, dirs, nondirs in os.walk(build_dir):
        for name in nondirs:
            if name.lower().endswith(".pyd") or name.lower().endswith(".so"):
                found_pyd = True
                old_path = os.path.join(top, name)
                new_path = os.path.join(pyx_dir, name)
                if os.path.exists(new_path):
                    print(f"removing {new_path}")
                    os.remove(new_path)
                print(f"file created at {new_path}")
                os.rename(old_path, new_path)
    if not found_pyd:
        raise RuntimeError("Never found .pyd file to move")

def run(pyx_path):
    """
    :param pyx_path:
    :type pyx_path:
    :return: this function creates the batch file, which in turn calls this module, which calls cythonize, once done
    the batch script deletes itself... I'm sure theres a less convoluted way of doing this, but it works
    :rtype:
    """
    try:
        project_name = os.path.splitext(os.path.basename(pyx_path))[0]
        run_script(project_name, os.path.abspath(pyx_path))
    except:
        input(format_exc())


def run_script(project_name, pyx_path):
    dirname = os.path.dirname(pyx_path)
    # ------------------------------
    os.chdir(dirname)
    if os.path.exists(vcvars):
        #  raise RuntimeError(
        # f"Could not find vcvars32.bat at {vcvars}\nis Visual Studio Installed?\nIs setuptools version > 34?")
        subprocess.check_call(f'call "{vcvars}"', shell=True)

    cmd = "python" if platform.system() == "Windows" else "python3"
    subprocess.check_call(f'{cmd} "{__file__}" build_ext "{project_name}" "{pyx_path}"', shell=True)
    move_pyd_files(pyx_path)
    cleanup(pyx_path)


if len(sys.argv) > 2:
    _build_ext()

回答 25

使用此链接下载和安装Visual C ++ 2015生成工具。它会自动下载visualcppbuildtools_full.exe并安装Visual C ++ 14.0,而无需实际安装Visual Studio。安装完成后,重试pip安装,您将不会再次收到错误。

我已经在以下平台和版本上对其进行了测试:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

Use this link to download and install Visual C++ 2015 Build Tools. It will automatically download visualcppbuildtools_full.exe and install Visual C++ 14.0 without actually installing Visual Studio. After the installation completes, retry pip install and you won’t get the error again.

I have tested it on following platform and versions:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

回答 26

如果要在安装Visual Studio 的Windows机器上安装pyodbc,另一个选择是使用二进制发行版手动安装pyodbc。

如果您在使用的计算机上没有管理员特权并尝试设置virtualenv,则此功能特别有用

脚步:

  1. 此处下载最新的Windows安装程序(pyodbc-XXXwin-Y-py2.7.exe)
  2. 使用7-Zip(或WinRAR或其他工具)打开安装程序可执行文件
  3. 提取pyodbc.pyd和pyodbc-XXX-py2.7.egg-info并将它们放在 [python installation directory or virtualenv]\Lib\site-packages
  4. 没有步骤4 :)

If you’re looking to install pyodbc on a Windows box that doesn’t have Visual Studio installed another option is to manually install pyodbc using the binary distribution.

This is particularly useful if you do not have administrator privileges on the machine you’re working with and are trying to set up a virtualenv.

Steps:

  1. Download the latest Windows installer from here (pyodbc-X.X.X.win-Y-py2.7.exe)
  2. Open the installer executable using 7-Zip (or WinRAR or whatever)
  3. Extract pyodbc.pyd and pyodbc-X.X.X-py2.7.egg-info and place them in [python installation directory or virtualenv]\Lib\site-packages
  4. There is no step 4 :)

回答 27

使用Python 3.4,依赖关系依赖于Visual Studio2010。安装Visual C ++ 2010 Express对我来说解决了这个问题。

欺骗我使用我碰巧无法使用的VS 2008或2013安装。

With Python 3.4, the dependency is on Visual Studio 2010. Installing Visual C++ 2010 Express fixed the problem for me.

Tricking it into using the VS 2008 or 2013 installs that I happened to have didn’t work.


回答 28

您可以使用easy_install代替pip,它对我有用。

You can use easy_install instead of pip it works for me.


回答 29

@monkey给出的答案是正确的答案之一,但不完整。

如果您想使用MinGW,则应该选择C,C ++以及在MinGW安装过程中建议的其他开发工具,以获取“ make.exe”。

您还必须在环境中将路径设置为make.exe。

要完成他的回答,请按以下步骤操作:

  1. 将mingw32的bin目录添加到您的环境变量中
  2. 附加 C:\Programs\MinGW\bin;C:\Programs\MinGW\msys\1.0\bin;到PATH
  3. 编辑distutils.cfg位于以下位置的文件(如果不存在则创建)C:\Python26\Lib\distutils\distutils.cfg

    [build]
    compiler=mingw32

通过打开新的cmd.exe确保设置了环境变量。

The answer given by @monkey is one of the correct ones, but it is incomplete.

In case you’d like to use MinGW, you should select the C, C++ and also other development tools suggested during the MinGW installation process to also get “make.exe.”

You must also have the path set to make.exe in the env.

To complete his answer, here are the steps:

  1. Add mingw32’s bin directory to your environment variables
  2. Append C:\Programs\MinGW\bin;C:\Programs\MinGW\msys\1.0\bin; to the PATH
  3. Edit (create if it doesn’t exist) the distutils.cfg file located at C:\Python26\Lib\distutils\distutils.cfg to be:

    [build]
    compiler=mingw32
    

Make sure the environment variables is set by opening a new cmd.exe.


Gitsome-增强型Git/GitHub命令行界面(CLI)。GitHub和GitHub企业的官方集成:https://github.com/works-with/category/desktop-tools

一个Official Integration对于GitHub和GitHub Enterprise

为什么gitsome

Git命令行

虽然标准的Git命令行是管理基于Git的repo的一个很好的工具,但是它可以很难记住这个用法地址为:

  • 150多个瓷器和管道命令
  • 无数特定于命令的选项
  • 标签和分支等资源

Git命令行不与GitHub集成,强制您在命令行和浏览器之间切换

gitsome-具有自动完成功能的增压Git/GitHub CLI

gitsome旨在通过专注于以下方面来增强您的标准git/shell界面:

  • 提高易用性
  • 提高工作效率

深度GitHub集成

并不是所有的GitHub工作流都能在终端中很好地工作;gitsome试图将目标对准那些这样做的人

gitsome包括29个与一起使用的GitHub集成命令ALL外壳:

$ gh <command> [param] [options]

gh命令以及Git-Extrashub解锁更多GitHub集成的命令!

带有交互式帮助的Git和GitHub自动完成程序

您可以运行可选壳牌:

 $ gitsome

要启用自动完成交互式帮助对于以下内容:

通用自动补全程序

gitsome自动完成以下内容:

  • Shell命令
  • 文件和目录
  • 环境变量
  • 手册页
  • python

要启用其他自动完成,请查看Enabling Bash Completions部分

鱼式自动建议

gitsome支持鱼式自动建议。使用right arrow完成建议的关键

Python REPL

gitsome由以下人员提供动力xonsh,它支持Python REPL

在shell命令旁边运行Python命令:

附加内容xonsh功能可在xonsh tutorial

命令历史记录

gitsome跟踪您输入的命令并将其存储在~/.xonsh_history.json使用向上和向下箭头键循环查看命令历史记录

可自定义的突出显示

可以控制用于突出显示的ansi颜色,方法是更新~/.gitsomeconfig文件

颜色选项包括:

'black', 'red', 'green', 'yellow',
'blue', 'magenta', 'cyan', 'white'

对于无颜色,请将值设置为Nonewhite在某些终端上可能显示为浅灰色

可用的平台

gitsome适用于Mac、Linux、Unix、Windows,以及Docker

待办事项

并不是所有的GitHub工作流都能在终端中很好地工作;gitsome试图将目标对准那些这样做的人

  • 添加其他GitHub API集成

gitsome才刚刚开始。请随意……contribute!

索引

GitHub集成命令

安装和测试

杂项

GitHub集成命令语法

用法:

$ gh <command> [param] [options]

GitHub集成命令列表

  configure            Configure gitsome.
  create-comment       Create a comment on the given issue.
  create-issue         Create an issue.
  create-repo          Create a repo.
  emails               List all the user's registered emails.
  emojis               List all GitHub supported emojis.
  feed                 List all activity for the given user or repo.
  followers            List all followers and the total follower count.
  following            List all followed users and the total followed count.
  gitignore-template   Output the gitignore template for the given language.
  gitignore-templates  Output all supported gitignore templates.
  issue                Output detailed information about the given issue.
  issues               List all issues matching the filter.
  license              Output the license template for the given license.
  licenses             Output all supported license templates.
  me                   List information about the logged in user.
  notifications        List all notifications.
  octo                 Output an Easter egg or the given message from Octocat.
  pull-request         Output detailed information about the given pull request.
  pull-requests        List all pull requests.
  rate-limit           Output the rate limit.  Not available for Enterprise.
  repo                 Output detailed information about the given filter.
  repos                List all repos matching the given filter.
  search-issues        Search for all issues matching the given query.
  search-repos         Search for all repos matching the given query.
  starred              Output starred repos.
  trending             List trending repos for the given language.
  user                 List information about the given user.
  view                 View the given index in the terminal or a browser.

GitHub集成命令参考:COMMANDS.md

请参阅GitHub Integration Commands Reference in COMMANDS.md对于详细讨论所有GitHub集成命令、参数、选项和示例

请查看下一节,了解快速参考

GitHub集成命令快速参考

配置gitsome

要与GitHub正确集成,您必须首先配置gitsome

$ gh configure

对于GitHub Enterprise用户,使用-e/--enterprise标志:

$ gh configure -e

列表源

列出您的新闻源

$ gh feed

列出用户的活动摘要

查看您的活动订阅源或其他用户的活动订阅源,也可以选择使用寻呼机-p/--pager这个pager option可用于许多命令

$ gh feed donnemartin -p

列出回购的活动提要

$ gh feed donnemartin/gitsome -p

列出通知

$ gh notifications

列出拉式请求

查看您的回购的所有拉式请求:

$ gh pull-requests

过滤问题

查看您提到的所有未决问题:

$ gh issues --issue_state open --issue_filter mentioned

查看所有问题,只筛选分配给您的问题,而不考虑状态(打开、关闭):

$ gh issues --issue_state all --issue_filter assigned

有关过滤和州限定词的更多信息,请访问gh issues参考位置COMMANDS.md

过滤星级报告

$ gh starred "repo filter"

搜索问题和报告

搜索问题

+1最多的搜索问题:

$ gh search-issues "is:open is:issue sort:reactions-+1-desc" -p

评论最多的搜索问题:

$ gh search-issues "is:open is:issue sort:comments-desc" -p

使用“需要帮助”标签搜索问题:

$ gh search-issues "is:open is:issue label:\"help wanted\"" -p

已标记您的用户名的搜索问题@donnemartin

$ gh search-issues "is:issue donnemartin is:open" -p

搜索您所有未解决的私人问题:

$ gh search-issues "is:open is:issue is:private" -p

有关查询限定符的更多信息,请访问searching issues reference

搜索报告

搜索2015年或之后创建的所有Python repos,>=1000星:

$ gh search-repos "created:>=2015-01-01 stars:>=1000 language:python" --sort stars -p

有关查询限定符的更多信息,请访问searching repos reference

列出趋势报告和开发人员

查看趋势回购:

$ gh trending [language] [-w/--weekly] [-m/--monthly] [-d/--devs] [-b/--browser]

查看趋势DEV(目前仅浏览器支持DEV):

$ gh trending [language] --devs --browser

查看内容

这个view命令

查看前面列出的通知、拉取请求、问题、回复、用户等,HTML格式适合您的终端,也可以选择在您的浏览器中查看:

$ gh view [#] [-b/--browser]

这个issue命令

查看问题:

$ gh issue donnemartin/saws/1

这个pull-request命令

查看拉取请求:

$ gh pull-request donnemartin/awesome-aws/2

设置.gitignore

列出所有可用的.gitignore模板:

$ gh gitignore-templates

设置您的.gitignore

$ gh gitignore-template Python > .gitignore

设置LICENSE

列出所有可用的LICENSE模板:

$ gh licenses

设置您的或LICENSE

$ gh license MIT > LICENSE

召唤十月猫

在十月猫那天打电话说出给定的信息或复活节彩蛋:

$ gh octo [say]

查看配置文件

查看用户的配置文件

$ gh user octocat

查看您的个人资料

使用查看您的个人资料gh user [YOUR_USER_ID]命令或使用以下快捷方式:

$ gh me

创建评论、问题和报告

创建评论:

$ gh create-comment donnemartin/gitsome/1 -t "hello world"

创建问题:

$ gh create-issue donnemartin/gitsome -t "title" -b "body"

创建回购:

$ gh create-repo gitsome

选项:在寻呼机中查看

许多gh命令支持-p/--pager在寻呼机中显示结果的选项(如果可用)

用法:

$ gh <command> [param] [options] -p
$ gh <command> [param] [options] --pager

选项:在浏览器中查看

许多gh命令支持-b/--browser在默认浏览器(而不是终端)中显示结果的选项

用法:

$ gh <command> [param] [options] -b
$ gh <command> [param] [options] --browser

请参阅COMMANDS.md有关所有GitHub集成命令、参数、选项和示例的详细列表

记住这些命令有困难吗?看看手边的autocompleter with interactive help来指导您完成每个命令

注意,您可以将gitsome与其他实用程序(如Git-Extras

安装

PIP安装

gitsome托管在PyPI将安装以下命令gitsome

$ pip3 install gitsome

您还可以安装最新的gitsome来自GitHub源,可能包含尚未推送到PyPI的更改:

$ pip3 install git+https://github.com/donnemartin/gitsome.git

如果您没有安装在virtualenv,您可能需要运行sudo

$ sudo pip3 install gitsome

pip3

根据您的设置,您可能还希望运行pip3使用-H flag

$ sudo -H pip3 install gitsome

对于大多数Linux用户来说,pip3可以使用python3-pip套餐

例如,Ubuntu用户可以运行:

$ sudo apt-get install python3-pip

看这个ticket有关更多详细信息,请参阅

虚拟环境安装

您可以将Python包安装在virtualenv要避免依赖项或权限的潜在问题,请执行以下操作

如果您是Windows用户,或者如果您想了解更多有关virtualenv,看看这个guide

安装virtualenvvirtualenvwrapper

$ pip3 install virtualenv
$ pip3 install virtualenvwrapper
$ export WORKON_HOME=~/.virtualenvs
$ source /usr/local/bin/virtualenvwrapper.sh

创建gitsomevirtualenv并安装gitsome

$ mkvirtualenv gitsome
$ pip3 install gitsome

如果pip安装不起作用,您可能默认运行的是Python2。检查您正在运行的Python版本:

$ python --version

如果上面的调用结果是Python 2,请找到Python 3的路径:

$ which python3  # Python 3 path for mkvirtualenv's --python option

如果需要,安装Python 3。调用时设置Python版本mkvirtualenv

$ mkvirtualenv --python [Python 3 path from above] gitsome
$ pip3 install gitsome

如果要激活gitsomevirtualenv稍后再次运行:

$ workon gitsome

要停用gitsomevirtualenv,运行:

$ deactivate

作为Docker容器运行

您可以在Docker容器中运行gitome,以避免安装Python和pip3当地的。要安装Docker,请查看official Docker documentation

一旦安装了docker,您就可以运行gitome:

$ docker run -ti --rm mariolet/gitsome

您可以使用Docker卷让gitome访问您的工作目录、本地的.gitSomeconfig和.gitconfig:

$ docker run -ti --rm -v $(pwd):/src/              \
   -v ${HOME}/.gitsomeconfig:/root/.gitsomeconfig  \
   -v ${HOME}/.gitconfig:/root/.gitconfig          \
   mariolet/gitsome

如果您经常运行此命令,则可能需要定义别名:

$ alias gitsome="docker run -ti --rm -v $(pwd):/src/              \
                  -v ${HOME}/.gitsomeconfig:/root/.gitsomeconfig  \
                  -v ${HOME}/.gitconfig:/root/.gitconfig          \
                  mariolet/gitsome"

要从源构建Docker映像,请执行以下操作:

$ git clone https://github.com/donnemartin/gitsome.git
$ cd gitsome
$ docker build -t gitsome .

启动gitsome

安装后,运行可选的gitsome带有交互式帮助的自动完成程序:

$ gitsome

运行可选的gitsomeShell将为您提供自动完成、交互式帮助、鱼式建议、Python REPL等

正在运行gh命令

运行GitHub集成命令:

$ gh <command> [param] [options]

注意:运行gitsome不需要执行外壳程序gh命令。之后installinggitsome你可以跑gh来自任何shell的命令

运行gh configure命令

要与GitHub正确集成,gitsome必须正确配置:

$ gh configure

针对GitHub企业用户

使用-e/--enterprise标志:

$ gh configure -e

要查看更多详细信息,请访问gh configure部分

启用Bash完成

默认情况下,gitsome查看以下内容locations to enable bash completions

要添加其他bash完成,请更新~/.xonshrc包含bash完成位置的文件

如果~/.xonshrc不存在,请创建它:

$ touch ~/.xonshrc

例如,如果在/usr/local/etc/my_bash_completion.d/completion.bash,将以下行添加到~/.xonshrc

$BASH_COMPLETIONS.append('/usr/local/etc/my_bash_completion.d/completion.bash')

您将需要重新启动gitsome要使更改生效,请执行以下操作

正在启用gh在外部完成制表符gitsome

你可以跑gh外部的命令gitsome外壳完成器。要启用gh此工作流的制表符完成,请将gh_complete.sh本地文件

让bash知道可以完成gh当前会话中的命令:

$ source /path/to/gh_complete.sh

要为所有终端会话启用制表符完成,请将以下内容添加到您的bashrc文件:

source /path/to/gh_complete.sh

重新加载您的bashrc

$ source ~/.bashrc

提示:.是的缩写source,因此您可以改为运行以下命令:

$ . ~/.bashrc

对于Zsh用户

zsh包括与bash完成兼容的模块

下载gh_complete.sh文件,并将以下内容附加到您的.zshrc

autoload bashcompinit
bashcompinit
source /path/to/gh_complete.sh

重新加载您的zshrc

 $ source ~/.zshrc

可选:安装PILPillow

将化身显示为gh megh user命令需要安装可选的PILPillow依赖性

Windows*和Mac:

$ pip3 install Pillow

*请参阅Windows Support有关化身限制的部分

Ubuntu用户,看看这些instructions on askubuntu

支持的Python版本

  • Python 3.4
  • Python 3.5
  • Python 3.6
  • Python 3.7

gitsome由以下人员提供动力xonsh,它当前不支持Python2.x,如本文中所讨论的ticket

支持的平台

  • Mac OS X
    • 在OS X 10.10上测试
  • Linux、Unix
    • 在Ubuntu 14.04 LTS上测试
  • 窗口
    • 在Windows 10上测试

Windows支持

gitsome已在Windows 10上进行了测试,cmdcmder

虽然您可以使用标准的Windows命令提示符,但使用这两种命令提示符都可能会有更好的体验cmderconemu

纯文本化身

命令gh usergh me将永远拥有-t/--text_avatar标志已启用,因为img2txt不支持Windows上的ANSI头像

配置文件

在Windows上,.gitsomeconfig 文件可在以下位置找到%userprofile%例如:

C:\Users\dmartin\.gitsomeconfig

开发人员安装

如果您有兴趣为gitsome,请运行以下命令:

$ git clone https://github.com/donnemartin/gitsome.git
$ cd gitsome
$ pip3 install -e .
$ pip3 install -r requirements-dev.txt
$ gitsome
$ gh <command> [param] [options]

pip3

如果您在安装时收到一个错误,提示您需要Python 3.4+,这可能是因为您的pip命令是为旧版本的Python配置的。要解决此问题,建议安装pip3

$ sudo apt-get install python3-pip

看这个ticket有关更多详细信息,请参阅

持续集成

有关持续集成的详细信息,请访问Travis CI

单元测试和代码覆盖率

在活动的Python环境中运行单元测试:

$ python tests/run_tests.py

使用运行单元测试tox在多个Python环境中:

$ tox

文档

源代码文档将很快在Readthedocs.org请查看source docstrings

运行以下命令构建文档:

$ scripts/update_docs.sh

贡献

欢迎投稿!

回顾Contributing Guidelines有关如何执行以下操作的详细信息,请执行以下操作:

  • 提交问题
  • 提交拉式请求

学分

联系信息

请随时与我联系,讨论任何问题、问题或评论

我的联系信息可以在我的GitHub page

许可证

我在开放源码许可下向您提供此存储库中的代码和资源。因为这是我的个人存储库,您获得的我的代码和资源的许可证来自我,而不是我的雇主(Facebook)

Copyright 2016 Donne Martin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Youtube-dl-gui-用wxPython编写的流行的youtube-dl的跨平台前端GUI

一款流行的跨平台前端GUIyoutube-dl用wxPython编写的媒体下载器。Supported sites

屏幕截图

要求

下载次数

安装

从源安装

  1. 下载并解压缩源代码
  2. 将目录更改为youtube-dl-gui-0.4
  3. python setup.py install

安装PyPi

  1. pip install youtube-dlg

安装Windows Installer

  1. 下载并解压缩Windows Installer
  2. 运行setup.exe文件

贡献

作者

看见AUTHORS文件

许可证

这个Public Domain License

常见问题解答

看见FAQs文件

谢谢

感谢为这个项目做出贡献的每一个人,感谢@philipzae用于设计新的UI布局

如何在Windows上安装pip?

问题:如何在Windows上安装pip?

pip是的替代品easy_install。但是我应该在Windows上pip使用安装easy_install吗?有没有更好的办法?

pip is a replacement for easy_install. But should I install pip using easy_install on Windows? Is there a better way?


回答 0

Python 2.7.9+和3.4+

好消息!Pip随附了Python 3.4(2014年3月发布)和Python 2.7.9(2014年12月发布)。这是所有Python版本中的最佳功能。它使每个人都可以访问社区丰富的图书馆。新手不再因设置的困难而无法使用社区库。在与软件包管理器一起交付时,Python加入了RubyNode.jsHaskellPerlGo以及几乎所有其他具有主流开源社区的当代语言。谢谢,Python。

如果确实发现在使用Python 3.4+或Python 2.7.9+时不可用pip,则只需执行例如:

py -3 -m ensurepip

当然,这并不意味着Python打包已解决问题。经验仍然令人沮丧。我将在“堆栈溢出”问题中对此进行讨论。Python是否具有程序包/模块管理系统?

而且,对使用Python 2.7.8或更早版本(社区中相当大的一部分)的每个人来说都可惜。没有计划将Pip运送给您。遵循手册说明。

Python 2≤2.7.8和Python 3≤3.3

面对“包括电池”的座右铭,Python出厂时没有软件包管理器。更糟糕的是,直到最近,Pip一直很难安装。

官方指示

根据https://pip.pypa.io/zh-CN/stable/installing/#do-i-need-to-install-pip

下载时get-pip.py,请小心保存为.py文件而不是文件.txt。然后,在命令提示符下运行它:

python get-pip.py

您可能需要管理员命令提示符才能执行此操作。按照以管理员身份启动命令提示符(Microsoft TechNet)。

这将安装pip程序包,该程序包(在Windows中)包含… \ Scripts \ pip.exe,该路径必须位于PATH环境变量中才能从命令行使用pip(请参阅“替代说明”的第二部分,将其添加到您的路径,

替代说明

官方文档告诉用户从源代码安装Pip及其每个依赖项。对于新手来说,这是乏味的,对新手来说却是困难重重。

为了我们的缘故,Christoph Gohlke .msi为流行的Python软件包准备了Windows安装程序()。他为所有32位和64位Python版本构建安装程序。你需要:

  1. 安装setuptools
  2. 安装点子

对我来说,此安装点位于C:\Python27\Scripts\pip.exepip.exe在您的计算机上查找,然后将其文件夹(例如C:\Python27\Scripts)添加到您的路径(开始/编辑环境变量)。现在,您应该可以从命令行运行pip了。尝试安装软件包:

pip install httpie

你去了(希望)!常见问题的解决方案如下:

代理问题

如果您在办公室工作,则可能位于HTTP代理后面。如果是这样,请设置环境变量http_proxyhttps_proxy。大多数Python应用程序(和其他免费软件)都遵守这些规定。语法示例:

http://proxy_url:port
http://username:password@proxy_url:port

如果您真的不走运,则您的代理可以是Microsoft NTLM代理。自由软件无法应付。唯一的解决方案是安装一个免费软件友好代理,该代理转发给讨厌的代理。http://cntlm.sourceforge.net/

找不到vcvarsall.bat

Python模块可以部分用C或C ++编写。Pip尝试从源代码进行编译。如果没有安装和配置C / C ++编译器,则会看到此错误消息。

错误:找不到vcvarsall.bat

您可以通过安装C ++编译器(例如MinGWVisual C ++)来解决此问题。微软实际上提供了一个专门用于Python的工具。或尝试使用Microsoft Visual C ++编译器Python 2.7

尽管通常更容易检查Christoph网站上的包裹。

Python 2.7.9+ and 3.4+

Good news! Python 3.4 (released March 2014) and Python 2.7.9 (released December 2014) ship with Pip. This is the best feature of any Python release. It makes the community’s wealth of libraries accessible to everyone. Newbies are no longer excluded from using community libraries by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Node.js, Haskell, Perl, Go—almost every other contemporary language with a majority open-source community. Thank you, Python.

If you do find that pip is not available when using Python 3.4+ or Python 2.7.9+, simply execute e.g.:

py -3 -m ensurepip

Of course, that doesn’t mean Python packaging is problem solved. The experience remains frustrating. I discuss this in the Stack Overflow question Does Python have a package/module management system?.

And, alas for everyone using Python 2.7.8 or earlier (a sizable portion of the community). There’s no plan to ship Pip to you. Manual instructions follow.

Python 2 ≤ 2.7.8 and Python 3 ≤ 3.3

Flying in the face of its ‘batteries included’ motto, Python ships without a package manager. To make matters worse, Pip was—until recently—ironically difficult to install.

Official instructions

Per https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip:

Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt:

python get-pip.py

You possibly need an administrator command prompt to do this. Follow Start a Command Prompt as an Administrator (Microsoft TechNet).

This installs the pip package, which (in Windows) contains …\Scripts\pip.exe that path must be in PATH environment variable to use pip from the command line (see the second part of ‘Alternative Instructions’ for adding it to your PATH,

Alternative instructions

The official documentation tells users to install Pip and each of its dependencies from source. That’s tedious for the experienced and prohibitively difficult for newbies.

For our sake, Christoph Gohlke prepares Windows installers (.msi) for popular Python packages. He builds installers for all Python versions, both 32 and 64 bit. You need to:

  1. Install setuptools
  2. Install pip

For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (for example, C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:

pip install httpie

There you go (hopefully)! Solutions for common problems are given below:

Proxy problems

If you work in an office, you might be behind an HTTP proxy. If so, set the environment variables http_proxy and https_proxy. Most Python applications (and other free software) respect these. Example syntax:

http://proxy_url:port
http://username:password@proxy_url:port

If you’re really unlucky, your proxy might be a Microsoft NTLM proxy. Free software can’t cope. The only solution is to install a free software friendly proxy that forwards to the nasty proxy. http://cntlm.sourceforge.net/

Unable to find vcvarsall.bat

Python modules can be partly written in C or C++. Pip tries to compile from source. If you don’t have a C/C++ compiler installed and configured, you’ll see this cryptic error message.

Error: Unable to find vcvarsall.bat

You can fix that by installing a C++ compiler such as MinGW or Visual C++. Microsoft actually ships one specifically for use with Python. Or try Microsoft Visual C++ Compiler for Python 2.7.

Often though it’s easier to check Christoph’s site for your package.


回答 1

过时的 -使用分发,而不是此处所述的setuptools。-
过时的#2 -使用作为setuptools的分配已经过时了。

如前所述,pip不包含独立的安装程序,但是您可以使用其前身easy_install进行安装。

所以:

  1. 从此处下载最新的pip版本:http : //pypi.python.org/pypi/pip#downloads
  2. 解压缩
  3. 下载适用于Windows的最后一个简易安装程序:(http://pypi.python.org/pypi/setuptools底部下载.exe)。安装它。
  4. 将未压缩的pip文件夹内容复制到C:\Python2x\文件夹中(不要将整个文件夹复制到其中,仅复制内容),因为python命令在C:\Python2x文件夹外部不起作用,然后运行: python setup.py install
  5. 将您的python添加C:\Python2x\Scripts到路径

大功告成

现在,您可以pip install package像在Linux中那样轻松地安装软件包:)

Outdated — use distribute, not setuptools as described here. —
Outdated #2 — use setuptools as distribute is deprecated.

As you mentioned pip doesn’t include an independent installer, but you can install it with its predecessor easy_install.

So:

  1. Download the last pip version from here: http://pypi.python.org/pypi/pip#downloads
  2. Uncompress it
  3. Download the last easy installer for Windows: (download the .exe at the bottom of http://pypi.python.org/pypi/setuptools ). Install it.
  4. copy the uncompressed pip folder content into C:\Python2x\ folder (don’t copy the whole folder into it, just the content), because python command doesn’t work outside C:\Python2x folder and then run: python setup.py install
  5. Add your python C:\Python2x\Scripts to the path

You are done.

Now you can use pip install package to easily install packages as in Linux :)


回答 2

2014年更新:

1)如果您安装了Python 3.4或更高版本,则pip包含在Python中,并且应该已经在您的系统上运行。

2)如果您运行的版本低于Python 3.4,或者由于某些原因未在Python 3.4中安装pip,则您可能会使用pip的官方安装脚本get-pip.py。pip安装程序现在可以为您获取setuptools,并且可以在不考虑体系结构(32位或64位)的情况下运行。

这里详细说明了安装说明,其中包括:

要安装或升级pip,请安全下载get-pip.py

然后运行以下命令(可能需要管理员访问权限):

python get-pip.py

要升级现有的设置工具(或分发),请运行 pip install -U setuptools

为了后代,我将在下面保留两组旧说明。

旧答案:

对于Windows版本的64位版本-由于ez_setup,64位Windows + Python以前需要使用单独的安装方法,但是我已经在运行32位Python和64位Python的64位Windows上测试了新的分发方法,现在您可以对所有版本的Windows / Python 2.7X使用相同的方法:

使用分配的OLD方法2

  1. 下载分发 -我投入了我的想法C:\Python27\ScriptsScripts如果目录不存在,请随意创建。
  2. 打开命令提示符(在Windows上,如果不使用PowerShell,则应检出connemu2),然后将()更改为下载到的目录。cddistribute_setup.py
  3. 运行distribute_setup :(python distribute_setup.py如果您的python安装目录未添加到路径中,则此方法将不起作用- 请在此处获得帮助
  4. 将当前目录更改Scripts为Python安装目录(C:\Python27\Scripts),或者将该目录以及Python基本安装目录添加至您的%PATH%环境变量。
  5. 使用新安装的setuptools安装pip: easy_install pip

除非您easy_install.exe位于目录中(C:\ Python27 \ Scripts将是Python 2.7的默认设置),或者您将该目录添加到路径中,否则最后一步将不起作用。

使用ez_setup的OLD方法1

从setuptools页面

下载ez_setup.py并运行它;它将下载适当的.egg文件并为您安装。(当前,由于distutils安装程序的兼容性问题,提供的.exe安装程序不支持Windows的64位版本的Python。

之后,您可以继续:

  1. 添加c:\Python2x\Scripts到Windows路径(用已安装的实际版本号替换xin Python2x
  2. 打开一个新的(!)DOS提示符。从那里运行easy_install pip

2014 UPDATE:

1) If you have installed Python 3.4 or later, pip is included with Python and should already be working on your system.

2) If you are running a version below Python 3.4 or if pip was not installed with Python 3.4 for some reason, then you’d probably use pip’s official installation script get-pip.py. The pip installer now grabs setuptools for you, and works regardless of architecture (32-bit or 64-bit).

The installation instructions are detailed here and involve:

To install or upgrade pip, securely download get-pip.py.

Then run the following (which may require administrator access):

python get-pip.py

To upgrade an existing setuptools (or distribute), run pip install -U setuptools

I’ll leave the two sets of old instructions below for posterity.

OLD Answers:

For Windows editions of the 64 bit variety – 64-bit Windows + Python used to require a separate installation method due to ez_setup, but I’ve tested the new distribute method on 64-bit Windows running 32-bit Python and 64-bit Python, and you can now use the same method for all versions of Windows/Python 2.7X:

OLD Method 2 using distribute:

  1. Download distribute – I threw mine in C:\Python27\Scripts (feel free to create a Scripts directory if it doesn’t exist.
  2. Open up a command prompt (on Windows you should check out conemu2 if you don’t use PowerShell) and change (cd) to the directory you’ve downloaded distribute_setup.py to.
  3. Run distribute_setup: python distribute_setup.py (This will not work if your python installation directory is not added to your path – go here for help)
  4. Change the current directory to the Scripts directory for your Python installation (C:\Python27\Scripts) or add that directory, as well as the Python base installation directory to your %PATH% environment variable.
  5. Install pip using the newly installed setuptools: easy_install pip

The last step will not work unless you’re either in the directory easy_install.exe is located in (C:\Python27\Scripts would be the default for Python 2.7), or you have that directory added to your path.

OLD Method 1 using ez_setup:

from the setuptools page

Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue.

After this, you may continue with:

  1. Add c:\Python2x\Scripts to the Windows path (replace the x in Python2x with the actual version number you have installed)
  2. Open a new (!) DOS prompt. From there run easy_install pip

回答 3

2016年更新:

这些答案已经过时,或者罗word且困难。

如果您拥有Python 3.4+或2.7.9+,它将默认安装在Windows上。否则,简而言之:

  1. 下载pip安装程序:https : //bootstrap.pypa.io/get-pip.py
  2. 如果偏执,请检查文件以确认它不是恶意的(必须b64解码)。
  3. 以Admin身份在下载文件夹中打开一个控制台,然后运行 get-pip.py。或者,在资源管理器中右键单击其图标,然后选择“以管理员身份运行…”。

新的二进制文件pip.exe(和已弃用的easy_install.exe)将在"%ProgramFiles%\PythonXX\Scripts"文件夹(或类似文件)中找到,该文件夹通常不在您的PATH变量中。我建议添加它。

2016+ Update:

These answers are outdated or otherwise wordy and difficult.

If you’ve got Python 3.4+ or 2.7.9+, it will be installed by default on Windows. Otherwise, in short:

  1. Download the pip installer: https://bootstrap.pypa.io/get-pip.py
  2. If paranoid, inspect file to confirm it isn’t malicious (must b64 decode).
  3. Open a console in the download folder as Admin and run get-pip.py. Alternatively, right-click its icon in Explorer and choose the “run as Admin…”.

The new binaries pip.exe (and the deprecated easy_install.exe) will be found in the "%ProgramFiles%\PythonXX\Scripts" folder (or similar), which is often not in your PATH variable. I recommend adding it.


回答 4

2014年3月 发布的Python 3.4 pip附带了以下内容:
http : //docs.python.org/3.4/whatsnew/3.4.html
因此,自Python 3.4发布以来,最新的安装pip方法在Windows上只是安装Python。

推荐的使用方式是将其称为模块,尤其是在安装了多个python发行版或版本的情况下,以确保程序包可以到达正确的位置:
python -m pip install --upgrade packageXYZ

https://docs.python.org/3/installing/#work-with-multiple-versions-of-python-installed-in-parallel

Python 3.4, which was released in March 2014, comes with pip included:
http://docs.python.org/3.4/whatsnew/3.4.html
So, since the release of Python 3.4, the up-to-date way to install pip on Windows is to just install Python.

The recommended way to use it is to call it as a module, especially with multiple python distributions or versions installed, to guarantee packages go to the correct place:
python -m pip install --upgrade packageXYZ

https://docs.python.org/3/installing/#work-with-multiple-versions-of-python-installed-in-parallel


回答 5

当我必须使用Windows时,我使用ActivePython,它将自动将所有内容添加到您的PATH中,并包括一个名为PyPM的软件包管理器,该软件包管理器提供了二进制软件包管理,从而使安装软件包变得更快,更简单。

pipeasy_install不是完全一样的东西,所以有一些事情可以打通pip,但不是easy_install ,反之亦然

我的建议是您获得ActivePython社区版,不要担心在Windows上为Python设置所有东西的麻烦。然后,您可以使用pypm

如果要使用pip,则必须检查PyPMActiveState安装程序中的选项。安装后,您只需要注销并再次登录,pip即可在命令行中使用,因为它包含在ActiveState安装程序PyPM选项中,并且安装程序已经为您设置了路径。PyPM也可以使用,但您不必使用它。

When I have to use Windows, I use ActivePython, which automatically adds everything to your PATH and includes a package manager called PyPM which provides binary package management making it faster and simpler to install packages.

pip and easy_install aren’t exactly the same thing, so there are some things you can get through pip but not easy_install and vice versa.

My recommendation is that you get ActivePython Community Edition and don’t worry about the huge hassle of getting everything set up for Python on Windows. Then, you can just use pypm.

In case you want to use pip you have to check the PyPM option in the ActiveState installer. After installation you only need to logoff and log on again, and pip will be available on the commandline, because it is contained in the ActiveState installer PyPM option and the paths have been set by the installer for you already. PyPM will also be available, but you do not have to use it.


回答 6

最新的方法是使用Windows的软件包管理器Chocolatey

安装完成后,您所要做的就是打开命令提示符并运行下面的以下三个命令,这将安装Python 2.7,easy_install和pip。它会自动检测您是在x64还是x86 Windows上。

cinst python
cinst easy.install
cinst pip

Chocolatey Gallery上的所有其他Python软件包都可以在这里找到。

The up-to-date way is to use Windows’ package manager Chocolatey.

Once this is installed, all you have to do is open a command prompt and run the following the three commands below, which will install Python 2.7, easy_install and pip. It will automatically detect whether you’re on x64 or x86 Windows.

cinst python
cinst easy.install
cinst pip

All of the other Python packages on the Chocolatey Gallery can be found here.


回答 7

2015年3月更新

Python 2.7.9和更高版本(在Python 2系列上)以及Python 3.4和更高版本默认情况下都包含pip,因此您可能已经拥有pip。

如果不这样做,请在提示符下运行以下一行命令(可能需要管理员访问权限):

python -c "exec('try: from urllib2 import urlopen \nexcept: from urllib.request import urlopen');f=urlopen('https://bootstrap.pypa.io/get-pip.py').read();exec(f)"

它将安装pip。如果尚未安装Setuptoolsget-pip.py也将为您安装它。

如评论中所述,以上命令将从GitHub上的Pip源代码存储库下载代码,并在您的环境中动态运行它。因此请注意,这是下载,检查和运行步骤的快捷方式,所有这些操作都使用Python本身通过一个命令完成。如果您信任Pip,请毫无疑问地继续。

确保Windows环境变量PATH包含Python的文件夹(对于Python 2.7.x,默认安装:C:\Python27C:\Python27\Scripts,对于Python 3.3x:C:\Python33C:\Python33\Scripts,依此类推)。

Update March 2015

Python 2.7.9 and later (on the Python 2 series), and Python 3.4 and later include pip by default, so you may have pip already.

If you don’t, run this one line command on your prompt (which may require administrator access):

python -c "exec('try: from urllib2 import urlopen \nexcept: from urllib.request import urlopen');f=urlopen('https://bootstrap.pypa.io/get-pip.py').read();exec(f)"

It will install pip. If Setuptools is not already installed, get-pip.py will install it for you too.

As mentioned in comments, the above command will download code from the Pip source code repository at GitHub, and dynamically run it at your environment. So be noticed that this is a shortcut of the steps download, inspect and run, all with a single command using Python itself. If you trust Pip, proceed without doubt.

Be sure that your Windows environment variable PATH includes Python’s folders (for Python 2.7.x default install: C:\Python27 and C:\Python27\Scripts, for Python 3.3x: C:\Python33 and C:\Python33\Scripts, and so on).


回答 8

安装人员

我内置的Windows安装两种分发PIP这里(其目标是使用pip,而无需任何引导用easy_install或保存和运行Python脚本):

在Windows上,只需先下载并安装distribute,然后pip从上面的链接下载即可。distribute上面的链接确实包含存根.exe安装程序,并且当前仅32位。我尚未在64位Windows上测试过效果。

在Windows上构建

将其重做为新版本的过程并不困难,我将其包含在此处以供参考。

建造 distribute

为了获得存根.exe文件,您需要具有Visual C ++编译器(显然也可以与MinGW一起编译)

hg clone https://bitbucket.org/tarek/distribute
cd distribute
hg checkout 0.6.27
rem optionally, comment out tag_build and tag_svn_revision in setup.cfg
msvc-build-launcher.cmd
python setup.py bdist_win32
cd ..
echo build is in distribute\dist

建造 pip

git clone https://github.com/pypa/pip.git
cd pip
git checkout 1.1
python setup.py bdist_win32
cd ..
echo build is in pip\dist

Installers

I’ve built Windows installers for both distribute and pip here (the goal being to use pip without having to either bootstrap with easy_install or save and run Python scripts):

On Windows, simply download and install first distribute, then pip from the above links. The distribute link above does contain stub .exe installers, and these are currently 32-bit only. I haven’t tested the effect on 64-bit Windows.

Building on Windows

The process to redo this for new versions is not difficult, and I’ve included it here for reference.

Building distribute

In order to get the stub .exe files, you need to have a Visual C++ compiler (it is apparently compilable with MinGW as well)

hg clone https://bitbucket.org/tarek/distribute
cd distribute
hg checkout 0.6.27
rem optionally, comment out tag_build and tag_svn_revision in setup.cfg
msvc-build-launcher.cmd
python setup.py bdist_win32
cd ..
echo build is in distribute\dist

Building pip

git clone https://github.com/pypa/pip.git
cd pip
git checkout 1.1
python setup.py bdist_win32
cd ..
echo build is in pip\dist

回答 9

以下内容适用于Python 2.7。保存此脚本并启动它:

https:

//raw.github.com/pypa/pip/master/contrib/get-pip.py安装了Pip,然后将路径添加到您的环境:

C:\Python27\Scripts

最后

pip install virtualenv

另外,您还需要Microsoft Visual C ++ 2008 Express才能获得良好的编译器,并在安装软件包时避免出现此类消息:

error: Unable to find vcvarsall.bat

如果您使用的是Windows 7的64位版本,则可能会在64位Windows 7上阅读64位Python安装问题,以成功安装Python可执行程序包(带有注册表项)。

The following works for Python 2.7. Save this script and launch it:

https://raw.github.com/pypa/pip/master/contrib/get-pip.py

Pip is installed, then add the path to your environment :

C:\Python27\Scripts

Finally

pip install virtualenv

Also you need Microsoft Visual C++ 2008 Express to get the good compiler and avoid these kind of messages when installing packages:

error: Unable to find vcvarsall.bat

If you have a 64-bit version of Windows 7, you may read 64-bit Python installation issues on 64-bit Windows 7 to successfully install the Python executable package (issue with registry entries).


回答 10

对于最新的Python下载-我在Windows上安装了python 3.6。您不必怀疑所需的一切都在那里,请屏息,我将向您展示如何做到这一点。

  1. 确保为我安装python的位置在以下目录中

现在,如果您在Windows上,让我们将python和pip添加到环境变量路径设置中,以便在任何地方键入pip或python都可以从安装它们的地方调用python aor pip。

因此,在屏幕上方“ SCRIPTS ” 下的文件夹下找到PIP,让我们在环境变量路径中添加Python和PIP。

快完成了,让我们用CMD进行测试以使用pip安装goole软件包。

pip install google

再见!

For latest Python Download – I have python 3.6 on windows. You don’t have to wonder everything you need is there , take a breath i will show you how to do it.

  1. make sure where you install python for me its was in the following directory

Now , lets add python and pip into environment variable path settings if you are on windows, so that typing pip or python anywhere call python aor pip from where they are installed.

So, PIP is found under the folder in above screen “SCRIPTS” Lets add Python and PIP in environment variable path.

Almost Done , Let test with CMD to install goole package using pip.

pip install google

BYE BYE!


回答 11

要在Python 2.x上全局安装pip ,如Adrián所述,easy_install似乎是最好的解决方案。

但是pip 的安装说明建议使用virtualenv,因为每个virtualenv都会自动安装pip。这不需要root用户访问权限或修改系统Python安装。

尽管安装virtualenv仍然需要easy_install。

2018更新:

Python 3.3+现在包含venv模块,可轻松创建虚拟环境,如下所示:

python3 -m venv /path/to/new/virtual/environment

请参阅有关在创建后激活环境的不同平台方法的文档,但通常为以下之一:

$ source <venv>/bin/activate 

C:\> <venv>\Scripts\activate.bat

To install pip globally on Python 2.x, easy_install appears to be the best solution as Adrián states.

However the installation instructions for pip recommend using virtualenv since every virtualenv has pip installed in it automatically. This does not require root access or modify your system Python installation.

Installing virtualenv still requires easy_install though.

2018 update:

Python 3.3+ now includes the venv module for easily creating virtual environments like so:

python3 -m venv /path/to/new/virtual/environment

See documentation for different platform methods of activating the environment after creation, but typically one of:

$ source <venv>/bin/activate 

C:\> <venv>\Scripts\activate.bat

回答 12

要使用pip,并不一定需要直接在系统中安装pip。您可以通过使用它virtualenv。您可以按照以下步骤操作:

我们通常需要为一个特定项目安装Python软件包。因此,现在创建一个项目文件夹,比方说myproject。

  • 从的解压缩文件夹中复制virtualenv.py文件virtualenv,并将其粘贴到myproject文件夹中

现在创建一个虚拟环境,在myproject文件夹中,如下所示说myvirtualenv

python virtualenv.py myvirtualenv

它会向您显示:

New python executable in myvirtualenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.

现在,您的虚拟环境myvirtualenv已在项目文件夹中创建。您可能会注意到,pip现在已安装在您的虚拟环境中。您需要做的就是使用以下命令激活虚拟环境。

myvirtualenv\Scripts\activate

您将在命令提示符下看到以下内容:

(myvirtualenv) PATH\TO\YOUR\PROJECT\FOLDER>pip install package_name

现在,您可以开始使用pip,但是请确保已激活虚拟环境,方法是查看提示左侧的内容。

这是在虚拟环境中安装pip的最简单方法之一,但是您需要随身携带virtualenv.py文件。

有关安装pip / virtualenv / virtualenvwrapper的更多方法,请访问thegauraw.tumblr.com

To use pip, it is not mandatory that you need to install pip in the system directly. You can use it through virtualenv. What you can do is follow these steps:

We normally need to install Python packages for one particular project. So, now create a project folder, let’s say myproject.

  • Copy the virtualenv.py file from the decompressed folder of virtualenv, and paste inside the myproject folder

Now create a virtual environment, let’s say myvirtualenv as follows, inside the myproject folder:

python virtualenv.py myvirtualenv

It will show you:

New python executable in myvirtualenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.

Now your virtual environment, myvirtualenv, is created inside your project folder. You might notice, pip is now installed inside you virtual environment. All you need to do is activate the virtual environment with the following command.

myvirtualenv\Scripts\activate

You will see the following at the command prompt:

(myvirtualenv) PATH\TO\YOUR\PROJECT\FOLDER>pip install package_name

Now you can start using pip, but make sure you have activated the virtualenv looking at the left of your prompt.

This is one of the easiest way to install pip i.e. inside virtual environment, but you need to have virtualenv.py file with you.

For more ways to install pip/virtualenv/virtualenvwrapper, you can refer to thegauraw.tumblr.com.


回答 13

我只是想为那些无法从Windows 64位安装setuptools的用户添加一个解决方案。在python.org上的此错误中讨论了该问题,截至本评论发布之日仍未解决。提到了一个简单的解决方法,它可以完美地工作。一次注册表更改对我来说很成功。

链接:http//bugs.python.org/issue6792#

适用于我的解决方案…:

为2.6+版本的Python添加此注册表设置:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

这很可能是您在Python 2.6+中已经拥有的注册表设置:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

显然,您将需要用正在运行的Python版本替换2.6版本。

I just wanted to add one more solution for those having issues installing setuptools from Windows 64-bit. The issue is discussed in this bug on python.org and is still unresolved as of the date of this comment. A simple workaround is mentioned and it works flawlessly. One registry change did the trick for me.

Link: http://bugs.python.org/issue6792#

Solution that worked for me…:

Add this registry setting for 2.6+ versions of Python:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

This is most likely the registry setting you will already have for Python 2.6+:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

Clearly, you will need to replace the 2.6 version with whatever version of Python you are running.


回答 14

更新于2016年: Pip应该已经包含在中Python 2.7.9+ or 3.4+,但是如果由于某种原因它不存在,则可以使用以下一种格式。

PS:

  1. 在大多数情况下,这已经可以满足要求,但是,如果有必要,请确保环境变量PATH包含Python的文件夹(例如,Python 2.7.x在Windows默认安装:C:\Python27 and C:\Python27\Scripts,for Python 3.3xC:\Python33 and C:\Python33\Scripts等)

  2. 我遇到同样的问题,然后在这里的官方网站上找到了这种最简单的方法(一行代码!): http //www.pip-installer.org/en/latest/installing.html

不敢相信那里有这么长的答案(也许已经过时了?)。对他们表示感谢,但请对这个简短的答案进行投票,以帮助更多的新手!

Updated at 2016 : Pip should already be included in Python 2.7.9+ or 3.4+, but if for whatever reason it is not there, you can use the following one-liner.

PS:

  1. This should already be satisfied in most cases but, if necessary, be sure that your environment variable PATH includes Python’s folders (for example, Python 2.7.x on Windows default install: C:\Python27 and C:\Python27\Scripts, for Python 3.3x: C:\Python33 and C:\Python33\Scripts, etc)

  2. I encounter same problem and then found such perhaps easiest way (one liner!) mentioned on official website here: http://www.pip-installer.org/en/latest/installing.html

Can’t believe there are so many lengthy (perhaps outdated?) answers out there. Feeling thankful to them but, please up-vote this short answer to help more new comers!


回答 15

到目前为止,我发现的最好方法就是两行代码:

curl http://python-distribute.org/distribute_setup.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

它已在Windows 8上使用PowerShell,Cmd和Git Bash(MinGW)进行了测试。

您可能想要将路径添加到您的环境。就像C:\Python33\Scripts

The best way I found so far, is just two lines of code:

curl http://python-distribute.org/distribute_setup.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

It was tested on Windows 8 with PowerShell, Cmd, and Git Bash (MinGW).

And you probably want to add the path to your environment. It’s somewhere like C:\Python33\Scripts.


回答 16

在这里,如何通过简单的方法安装pip。

  1. 这些内容复制并粘贴为get-pip.py文件
  2. get-pip.py复制并粘贴到python文件夹中。C:\Python27
  3. 双击获取get-pip.py文件,它将pip安装到您的计算机上。
  4. 现在您必须为C:\Python27\Scripts环境变量添加路径,因为它包含pip.exe文件。
  5. 现在您可以使用点子了。打开cmd并键入为
    pip install package_name

Here how to install pip with easy way.

  1. copy and paste these content in a file as get-pip.py
  2. copy and paste get-pip.py into python folder.C:\Python27
  3. Double click to get-pip.py file.it will install pip to your computer.
  4. Now you have to add C:\Python27\Scripts path to your enviroment variable.Because it includes pip.exe file.
  5. Now you are ready to use pip. Open cmd and type as
    pip install package_name

回答 17

PythonXY带有pip包括,除其他

PythonXY comes with pip included, among others.


回答 18

我在Windows上使用来自continuum.io 的跨平台Anaconda软件包管理器,它是可靠的。它具有虚拟环境管理功能以及具有常用功能(例如conda,pip)的功能齐全的外壳。

> conda install <package>               # access distributed binaries

> pip install <package>                 # access PyPI packages 

conda还附带了具有非Python依赖项(例如pandasnumpy等)的库的二进制文件。这在Windows上特别有用,因为可能很难正确编译C依赖项。

I use the cross-platform Anaconda package manager from continuum.io on Windows and it is reliable. It has virtual environment management and a fully featured shell with common utilities (e.g. conda, pip).

> conda install <package>               # access distributed binaries

> pip install <package>                 # access PyPI packages 

conda also comes with binaries for libraries with non-Python dependencies, e.g. pandas, numpy, etc. This proves useful particularly on Windows as it can be hard to correctly compile C dependencies.


回答 19

按照此处的说明进行安装时,我遇到了一些问题。我认为以相同的方式在每个Windows环境中安装非常棘手。就我而言,出于同一目的,我需要在同一台计算机上使用Python 2.6、2.7和3.3,这就是为什么我认为还有更多问题的原因。但是以下说明对我来说非常有效,因此可能要根据您的环境尝试使用此说明:

http://docs.python-guide.org/zh-CN/latest/starting/install/win/

另外,由于不同的环境,我发现使用虚拟环境非常有用,我的网站使用不同的库,最好将它们封装到一个文件夹中,查看说明,如果已安装PIP,则只需安装VirtualEnv:

pip install virtualenv

将所有文件运行到该文件夹​​中

virtualenv venv

几秒钟后,您将在venv文件夹中拥有一个包含所有内容的虚拟环境,要运行它,请运行venv / Scripts / activate.bat(停用环境很容易,请使用deactivate.bat)。您安装的每个库都将以venv \ Lib \ site-packages结尾,并且很容易将整个环境移动到某个地方。

我发现的唯一缺点是某些代码编辑器无法识别这种环境,并且由于未找到导入的库,因此您会在代码中看到警告。当然,有一些棘手的方法可以做到这一点,但编辑人员切记,虚拟环境如今非常普遍。

希望能帮助到你。

I had some issues installing in different ways when I followed instructions here. I think it’s very tricky to install in every Windows environment in the same way. In my case I need Python 2.6, 2.7 and 3.3 in the same machine for different purposes so that’s why I think there’re more problems. But the following instructions worked perfectly for me, so might be depending on your environment you should try this one:

http://docs.python-guide.org/en/latest/starting/install/win/

Also, due to the different environments I found incredible useful to use Virtual Environments, I had websites that use different libraries and it’s much better to encapsulate them into a single folder, check out the instructions, briefly if PIP is installed you just install VirtualEnv:

pip install virtualenv

Into the folder you have all your files run

virtualenv venv

And seconds later you have a virtual environment with everything in venv folder, to activate it run venv/Scripts/activate.bat (deactivate the environment is easy, use deactivate.bat). Every library you install will end up in venv\Lib\site-packages and it’s easy to move your whole environment somewhere.

The only downside I found is some code editors can’t recognize this kind of environments, and you will see warnings in your code because imported libraries are not found. Of course there’re tricky ways to do it but it would be nice editors keep in mind Virtual Environments are very normal nowadays.

Hope it helps.


回答 20

  1. 下载脚本:https : //raw.github.com/pypa/pip/master/contrib/get-pip.py
  2. 将其保存在驱动器上,例如C:\ pip-script \ get-pip.py
  3. 从命令提示符导航到该路径,然后运行“ python get-pip.py”

指南链接:http : //www.pip-installer.org/en/latest/installing.html#install-pip

注意:请确保还将这样的脚本路径(C:\ Python27 \ Scripts)添加到int%PATH%环境变量中。

  1. Download script: https://raw.github.com/pypa/pip/master/contrib/get-pip.py
  2. Save it on drive somewhere like C:\pip-script\get-pip.py
  3. Navigate to that path from command prompt and run ” python get-pip.py “

Guide link: http://www.pip-installer.org/en/latest/installing.html#install-pip

Note: Make sure scripts path like this (C:\Python27\Scripts) is added int %PATH% environment variable as well.


回答 21

很简单:

Step 1: wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
Step 2: wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
Step 2: python ez_setup.py
Step 3: python get-pip.py

(确保您的Python和Python脚本目录(例如C:\Python27C:\Python27\Scripts)在PATH中。)

It’s very simple:

Step 1: wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
Step 2: wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
Step 2: python ez_setup.py
Step 3: python get-pip.py

(Make sure your Python and Python script directory (for example, C:\Python27 and C:\Python27\Scripts) are in the PATH.)


回答 22

从2014年2月4日开始工作:):

如果您按照@Colonel Panic的建议尝试通过Windows安装程序文件从http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip安装pip ,则可能已成功安装了pip软件包管理器,但是您可能无法使用pip安装任何软件包。如果您查看pip.log文件,您可能还会遇到与尝试安装Beautiful Soup 4时遇到的SSL错误相同的错误:

Downloading/unpacking beautifulsoup4
  Getting page https://pypi.python.org/simple/beautifulsoup4/
  Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: **connection error: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed**
  Will skip URL https://pypi.python.org/simple/beautifulsoup4/ when looking for download links for beautifulsoup4

问题是OpenSSL的旧版本与pip 1.3.1及更高版本不兼容。目前,最简单的解决方法是安装不需要SSL的 pip 1.2.1

在Windows上安装Pip:

  1. https://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz下载pip 1.2.1
  2. 提取pip-1.2.1.tar.gz文件
  3. 将目录更改为提取的文件夹: cd <path to extracted folder>/pip-1.2.1
  4. python setup.py install
  5. 现在确保C:\Python27\Scripts位于PATH中,因为pip安装在C:\Python27\Scripts目录中,这与C:\Python27\Lib\site-packages通常安装Python软件包的位置不同

现在尝试使用pip安装任何软件包。

例如,要requests使用pip 安装软件包,请从cmd运行此命令:

pip install requests

哇!requests将成功安装,您将收到一条成功消息。

Working as of Feb 04 2014 :):

If you have tried installing pip through the Windows installer file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip as suggested by @Colonel Panic, you might have installed the pip package manager successfully, but you might be unable to install any packages with pip. You might also have got the same SSL error as I got when I tried to install Beautiful Soup 4 if you look in the pip.log file:

Downloading/unpacking beautifulsoup4
  Getting page https://pypi.python.org/simple/beautifulsoup4/
  Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: **connection error: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed**
  Will skip URL https://pypi.python.org/simple/beautifulsoup4/ when looking for download links for beautifulsoup4

The problem is an issue with an old version of OpenSSL being incompatible with pip 1.3.1 and above versions. The easy workaround for now, is to install pip 1.2.1, which does not require SSL:

Installing Pip on Windows:

  1. Download pip 1.2.1 from https://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
  2. Extract the pip-1.2.1.tar.gz file
  3. Change directory to the extracted folder: cd <path to extracted folder>/pip-1.2.1
  4. Run python setup.py install
  5. Now make sure C:\Python27\Scripts is in PATH because pip is installed in the C:\Python27\Scripts directory unlike C:\Python27\Lib\site-packages where Python packages are normally installed

Now try to install any package using pip.

For example, to install the requests package using pip, run this from cmd:

pip install requests

Whola! requests will be successfully installed and you will get a success message.


回答 23

如果您使用的是从python.org下载的Python 2> = 2.7.9或Python 3> = 3.4二进制文件,则已经安装了pip,但是您需要升级pip。

在Windows上可以轻松完成升级

转到Python命令行并在Python命令下运行

python -m pip install -U pip

使用get-pip.py安装

get-pip.py下载到同一文件夹或您选择的任何其他文件夹中。我假设您将从python.exe文件将其下载到同一文件夹中,然后运行此命令

python get-pip.py

Pip的安装指南非常干净和简单。

使用此工具,您应该可以在两分钟内开始使用Pip。

pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4 binaries downloaded from python.org, but you’ll need to upgrade pip.

On Windows upgrade can be done easily

Go to Python command line and run below Python command

python -m pip install -U pip

Installing with get-pip.py

Download get-pip.py in the same folder or any other folder of your choice. I am assuming you will download it in the same folder from you have python.exe file and run this command

python get-pip.py

Pip’s installation guide is pretty clean and simple.

Using this you should be able to get started with Pip in under two minutes.


回答 24

如果您甚至对pip版本有其他问题,可以尝试一下

pip install --trusted-host pypi.python.org --upgrade pip

if you even have other problems with pip version you can try this

pip install --trusted-host pypi.python.org --upgrade pip

回答 25

简单的CMD方法

使用CURL下载get-pip.py

curl --http1.1 https://bootstrap.pypa.io/get-pip.py --output get-pip.py

执行下载的python文件

python get-pip.py

然后将C:\Python37\Scripts路径添加到您的环境变量。假设Python37您的C盘中有一个文件夹,该文件夹的名称可能会因安装的python版本而异

现在,您可以通过运行来安装python软件包

pip install awesome_package_name

Simple CMD way

Use CURL to download get-pip.py

curl --http1.1 https://bootstrap.pypa.io/get-pip.py --output get-pip.py

Execute downloaded python file

python get-pip.py

Then add C:\Python37\Scripts path to your environment variable. Assumes that there is a Python37 folder in your C drive, that folder name may varied according to the installed python version

Now you can install python packages by running

pip install awesome_package_name

回答 26

Python2和安装PipPython3

  1. get-pip.py下载到计算机上的文件夹。
  2. 打开命令提示符,然后导航到包含的文件夹get-pip.py
  3. 运行以下命令:python get-pip.pypython3 get-pip.pypython3.6 get-pip.py,取决于哪个版本的python要安装pip
  4. 点现在应该安装了!

旧答案(仍然有效)

你有没有尝试过 ?

python -m ensurepip

这可能是在任何系统上安装pip的最简单方法。

Installing Pip for Python2 and Python3

  1. Download get-pip.py to a folder on your computer.
  2. Open a command prompt and navigate to the folder containing get-pip.py.
  3. Run the following command:python get-pip.py, python3 get-pip.py or python3.6 get-pip.py, depending on which version of python you want to install pip
  4. Pip should be now installed!

Old answer (still valid)

Have you tried ?

python -m ensurepip

it’s probably the easiest to install pip on any system.


回答 27

只需从此处https://pypi.python.org/pypi/setuptools#windows-simplified下载setuptools-15.2.zip(md5),然后运行ez_setup.py。

Just download setuptools-15.2.zip (md5), from here https://pypi.python.org/pypi/setuptools#windows-simplified , and run ez_setup.py.


回答 28

或者,您可以获得pip-Win,它是pip的多合一安装程序,并且virtualenv在Windows及其GUI上。

  • 从一个Python解释器(即版本)切换到另一个(包括py和pypy)
  • 查看所有已安装的软件包,以及它们是否为最新
  • 安装或升级软件包,或升级pip本身
  • 创建和删除虚拟环境,并在它们之间切换
  • 使用选定的解释器运行IDLE或其他Python脚本

Alternatively, you can get pip-Win which is an all-in-one installer for pip and virtualenv on Windows and its GUI.

  • Switch from one Python interpreter (i.e. version) to another (including py and pypy)
  • See all installed packages, and whether they are up-to-date
  • Install or upgrade a package, or upgrade pip itself
  • Create and delete virtual environments, and switch between them
  • Run the IDLE or another Python script, with the selected interpreter

回答 29

现在,它与Python捆绑在一起。您不需要安装它。

pip -V

这样可以检查是否已安装pip。在极少数情况下,如果未安装,请下载get-pip.py文件并使用python作为

python get-pip.py

Now, it is bundled with Python. You don’t need to install it.

pip -V

This is how you can check whether pip is installed or not. In rare case, if it is not installed, download get-pip.py file and run it with python as

python get-pip.py

Psutil-Python中用于进程和系统监控的跨平台库

摘要

psutil(进程和系统实用程序)是一个跨平台库,用于检索正在运行的进程系统利用率(CPU、内存、磁盘、网络、传感器)。它主要用于系统监控分析和限制进程资源正在运行的进程的管理它实现了经典UNIX命令行工具提供的许多功能,例如ps、top、iotop、lsof、netstat、ifconfig、free还有其他人。psutil目前支持以下平台:

  • Linux操作系统
  • 窗口
  • MacOS
  • FreeBSD、OpenBSDNetBSD
  • Sun Solaris
  • AIX

支持的Python版本包括2.62.73.4+PyPy

资金来源

虽然psutil是自由软件,并且将永远是自由软件,但该项目将从一些资金中获益良多。就时间而言,只对我一个人来说,跟上错误报告和维护已经变得很难持续了。如果您是一家大量使用psutil的公司,您可以考虑通过以下方式成为赞助商GitHub SponsorsOpen CollectivePayPal并将您的徽标显示在此处和标牌上doc

赞助商

add your logo

支持者




add your avatar

贡献

看见contributing guidelines

用法示例

这几乎代表了整个psutil api。

CPU

>>> import psutil
>>>
>>> psutil.cpu_times()
scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, nice=0.0)
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1)
...
4.0
5.9
3.8
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1, percpu=True)
...
[4.0, 6.9, 3.7, 9.2]
[7.0, 8.5, 2.4, 2.1]
[1.2, 9.0, 9.9, 7.2]
>>>
>>> for x in range(3):
...     psutil.cpu_times_percent(interval=1, percpu=False)
...
scputimes(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
>>>
>>> psutil.cpu_count()
4
>>> psutil.cpu_count(logical=False)
2
>>>
>>> psutil.cpu_stats()
scpustats(ctx_switches=20455687, interrupts=6598984, soft_interrupts=2134212, syscalls=0)
>>>
>>> psutil.cpu_freq()
scpufreq(current=931.42925, min=800.0, max=3500.0)
>>>
>>> psutil.getloadavg()  # also on Windows (emulated)
(3.14, 3.89, 4.67)

内存

>>> psutil.virtual_memory()
svmem(total=10367352832, available=6472179712, percent=37.6, used=8186245120, free=2181107712, active=4748992512, inactive=2758115328, buffers=790724608, cached=3500347392, shared=787554304)
>>> psutil.swap_memory()
sswap(total=2097147904, used=296128512, free=1801019392, percent=14.1, sin=304193536, sout=677842944)
>>>

磁盘

>>> psutil.disk_partitions()
[sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw', maxfile=255, maxpath=4096)]
>>>
>>> psutil.disk_usage('/')
sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
>>>
>>> psutil.disk_io_counters(perdisk=False)
sdiskio(read_count=719566, write_count=1082197, read_bytes=18626220032, write_bytes=24081764352, read_time=5023392, write_time=63199568, read_merged_count=619166, write_merged_count=812396, busy_time=4523412)
>>>

网络

>>> psutil.net_io_counters(pernic=True)
{'eth0': netio(bytes_sent=485291293, bytes_recv=6004858642, packets_sent=3251564, packets_recv=4787798, errin=0, errout=0, dropin=0, dropout=0),
 'lo': netio(bytes_sent=2838627, bytes_recv=2838627, packets_sent=30567, packets_recv=30567, errin=0, errout=0, dropin=0, dropout=0)}
>>>
>>> psutil.net_connections(kind='tcp')
[sconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED', pid=1254),
 sconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=43761), raddr=addr(ip='72.14.234.100', port=80), status='CLOSING', pid=2987),
 ...]
>>>
>>> psutil.net_if_addrs()
{'lo': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1', ptp=None),
        snicaddr(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None, ptp=None),
        snicaddr(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00', ptp=None)],
 'wlan0': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),
           snicaddr(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None, ptp=None),
           snicaddr(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}
>>>
>>> psutil.net_if_stats()
{'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536),
 'wlan0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100, mtu=1500)}
>>>

传感器

>>> import psutil
>>> psutil.sensors_temperatures()
{'acpitz': [shwtemp(label='', current=47.0, high=103.0, critical=103.0)],
 'asus': [shwtemp(label='', current=47.0, high=None, critical=None)],
 'coretemp': [shwtemp(label='Physical id 0', current=52.0, high=100.0, critical=100.0),
              shwtemp(label='Core 0', current=45.0, high=100.0, critical=100.0)]}
>>>
>>> psutil.sensors_fans()
{'asus': [sfan(label='cpu_fan', current=3200)]}
>>>
>>> psutil.sensors_battery()
sbattery(percent=93, secsleft=16628, power_plugged=False)
>>>

其他系统信息

>>> import psutil
>>> psutil.users()
[suser(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0, pid=1352),
 suser(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0, pid=1788)]
>>>
>>> psutil.boot_time()
1365519115.0
>>>

流程管理

>>> import psutil
>>> psutil.pids()
[1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224, 268, 1215,
 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355, 2637, 2774, 3932,
 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245, 4263, 4282, 4306, 4311,
 4312, 4313, 4314, 4337, 4339, 4357, 4358, 4363, 4383, 4395, 4408, 4433,
 4443, 4445, 4446, 5167, 5234, 5235, 5252, 5318, 5424, 5644, 6987, 7054,
 7055, 7071]
>>>
>>> p = psutil.Process(7055)
>>> p
psutil.Process(pid=7055, name='python3', status='running', started='09:04:44')
>>> p.name()
'python3'
>>> p.exe()
'/usr/bin/python3'
>>> p.cwd()
'/home/giampaolo'
>>> p.cmdline()
['/usr/bin/python', 'main.py']
>>>
>>> p.pid
7055
>>> p.ppid()
7054
>>> p.children(recursive=True)
[psutil.Process(pid=29835, name='python3', status='sleeping', started='11:45:38'),
 psutil.Process(pid=29836, name='python3', status='waking', started='11:43:39')]
>>>
>>> p.parent()
psutil.Process(pid=4699, name='bash', status='sleeping', started='09:06:44')
>>> p.parents()
[psutil.Process(pid=4699, name='bash', started='09:06:44'),
 psutil.Process(pid=4689, name='gnome-terminal-server', status='sleeping', started='0:06:44'),
 psutil.Process(pid=1, name='systemd', status='sleeping', started='05:56:55')]
>>>
>>> p.status()
'running'
>>> p.username()
'giampaolo'
>>> p.create_time()
1267551141.5019531
>>> p.terminal()
'/dev/pts/0'
>>>
>>> p.uids()
puids(real=1000, effective=1000, saved=1000)
>>> p.gids()
pgids(real=1000, effective=1000, saved=1000)
>>>
>>> p.cpu_times()
pcputimes(user=1.02, system=0.31, children_user=0.32, children_system=0.1, iowait=0.0)
>>> p.cpu_percent(interval=1.0)
12.1
>>> p.cpu_affinity()
[0, 1, 2, 3]
>>> p.cpu_affinity([0, 1])  # set
>>> p.cpu_num()
1
>>>
>>> p.memory_info()
pmem(rss=10915840, vms=67608576, shared=3313664, text=2310144, lib=0, data=7262208, dirty=0)
>>> p.memory_full_info()  # "real" USS memory usage (Linux, macOS, Win only)
pfullmem(rss=10199040, vms=52133888, shared=3887104, text=2867200, lib=0, data=5967872, dirty=0, uss=6545408, pss=6872064, swap=0)
>>> p.memory_percent()
0.7823
>>> p.memory_maps()
[pmmap_grouped(path='/lib/x8664-linux-gnu/libutil-2.15.so', rss=32768, size=2125824, pss=32768, shared_clean=0, shared_dirty=0, private_clean=20480, private_dirty=12288, referenced=32768, anonymous=12288, swap=0),
 pmmap_grouped(path='/lib/x8664-linux-gnu/libc-2.15.so', rss=3821568, size=3842048, pss=3821568, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=3821568, referenced=3575808, anonymous=3821568, swap=0),
 pmmap_grouped(path='[heap]',  rss=32768, size=139264, pss=32768, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=32768, referenced=32768, anonymous=32768, swap=0),
 pmmap_grouped(path='[stack]', rss=2465792, size=2494464, pss=2465792, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=2465792, referenced=2277376, anonymous=2465792, swap=0),
 ...]
>>>
>>> p.io_counters()
pio(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632, read_chars=456232, write_chars=517543)
>>>
>>> p.open_files()
[popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768),
 popenfile(path='/var/log/monit.log', fd=4, position=235542, mode='a', flags=33793)]
>>>
>>> p.connections(kind='tcp')
[pconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED'),
 pconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=43761), raddr=addr(ip='72.14.234.100', port=80), status='CLOSING')]
>>>
>>> p.num_threads()
4
>>> p.num_fds()
8
>>> p.threads()
[pthread(id=5234, user_time=22.5, system_time=9.2891),
 pthread(id=5237, user_time=0.0707, system_time=1.1)]
>>>
>>> p.num_ctx_switches()
pctxsw(voluntary=78, involuntary=19)
>>>
>>> p.nice()
0
>>> p.nice(10)  # set
>>>
>>> p.ionice(psutil.IOPRIO_CLASS_IDLE)  # IO priority (Win and Linux only)
>>> p.ionice()
pionice(ioclass=<IOPriority.IOPRIO_CLASS_IDLE: 3>, value=0)
>>>
>>> p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))  # set resource limits (Linux only)
>>> p.rlimit(psutil.RLIMIT_NOFILE)
(5, 5)
>>>
>>> p.environ()
{'LC_PAPER': 'it_IT.UTF-8', 'SHELL': '/bin/bash', 'GREP_OPTIONS': '--color=auto',
'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg',
 ...}
>>>
>>> p.as_dict()
{'status': 'running', 'num_ctx_switches': pctxsw(voluntary=63, involuntary=1), 'pid': 5457, ...}
>>> p.is_running()
True
>>> p.suspend()
>>> p.resume()
>>>
>>> p.terminate()
>>> p.kill()
>>> p.wait(timeout=3)
<Exitcode.EX_OK: 0>
>>>
>>> psutil.test()
USER         PID %CPU %MEM     VSZ     RSS TTY        START    TIME  COMMAND
root           1  0.0  0.0   24584    2240            Jun17   00:00  init
root           2  0.0  0.0       0       0            Jun17   00:00  kthreadd
...
giampaolo  31475  0.0  0.0   20760    3024 /dev/pts/0 Jun19   00:00  python2.4
giampaolo  31721  0.0  2.2  773060  181896            00:04   10:30  chrome
root       31763  0.0  0.0       0       0            00:05   00:00  kworker/0:1
>>>

进一步的流程API

>>> import psutil
>>> for proc in psutil.process_iter(['pid', 'name']):
...     print(proc.info)
...
{'pid': 1, 'name': 'systemd'}
{'pid': 2, 'name': 'kthreadd'}
{'pid': 3, 'name': 'ksoftirqd/0'}
...
>>>
>>> psutil.pid_exists(3)
True
>>>
>>> def on_terminate(proc):
...     print("process {} terminated".format(proc))
...
>>> # waits for multiple processes to terminate
>>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
>>>

Windows服务

>>> list(psutil.win_service_iter())
[<WindowsService(name='AeLookupSvc', display_name='Application Experience') at 38850096>,
 <WindowsService(name='ALG', display_name='Application Layer Gateway Service') at 38850128>,
 <WindowsService(name='APNMCP', display_name='Ask Update Service') at 38850160>,
 <WindowsService(name='AppIDSvc', display_name='Application Identity') at 38850192>,
 ...]
>>> s = psutil.win_service_get('alg')
>>> s.as_dict()
{'binpath': 'C:\\Windows\\System32\\alg.exe',
 'description': 'Provides support for 3rd party protocol plug-ins for Internet Connection Sharing',
 'display_name': 'Application Layer Gateway Service',
 'name': 'alg',
 'pid': None,
 'start_type': 'manual',
 'status': 'stopped',
 'username': 'NT AUTHORITY\\LocalService'}

使用psutil的项目

这里有一些我觉得特别有趣的:

港口

MMKV-微信开发的高效、小型的移动键值存储框架。适用于Android、iOS、MacOS、Windows和POSIX

MMKV是一种高效小的易于使用微信应用中使用的移动键值存储框架。它目前在以下位置可用安卓系统iOS/MacOSWin32POSIX

适用于Android的MMKV

功能

  • 高效MMKV使用mmap与文件保持内存同步,使用协议buf对值进行编码/解码,充分利用Android实现最佳性能
    • 多进程并发:MMKV支持进程间并发读写访问
  • 易于使用你可以边走边用MMKV。所有更改都会立即保存,否sync,否apply需要的呼叫数
  • 小的
    • 几个文件:MMKV包含进程锁、编码/解码助手和mmap逻辑等。真的很整洁
    • 二进制大小约为50K:MMKV在应用程序大小上为每个架构增加约50K,压缩后增加的更少(Apk)

快速入门

通过Maven安装

将以下行添加到build.gradle在您的应用程序模块上:

dependencies {
    implementation 'com.tencent:mmkv-static:1.2.10'
    // replace "1.2.10" with any available version
}

从1.2.8版本开始,MMKV已经已迁移到Maven Central旧版本(<=v1.2.7)仍可在JCenter上使用
有关其他安装选项,请参见Android Setup

快速教程

你可以边走边用MMKV。所有更改都会立即保存,否sync,否apply需要的呼叫数
在应用程序启动时设置MMKV,表示您的Application类中,添加以下行:

public void onCreate() {
    super.onCreate();

    String rootDir = MMKV.initialize(this);
    System.out.println("mmkv root: " + rootDir);
    //……
}

MMKV有一个全局实例,可以直接使用:

import com.tencent.mmkv.MMKV;
    
MMKV kv = MMKV.defaultMMKV();

kv.encode("bool", true);
boolean bValue = kv.decodeBool("bool");

kv.encode("int", Integer.MIN_VALUE);
int iValue = kv.decodeInt("int");

kv.encode("string", "Hello from mmkv");
String str = kv.decodeString("string");

MMKV还支持多进程访问完整的教程可在此处找到Android Tutorial

性能

随机写入int1000次之后,我们得到了这个图表:

有关更多基准数据,请参阅our benchmark

适用于iOS/MacOS的MMKV

功能

  • 高效MMKV使用mmap与文件保持内存同步,使用协议buf对值进行编码/解码,充分利用IOS/MacOS实现最佳性能
  • 易于使用你可以随时随地使用MMKV,不需要配置。所有更改都会立即保存,否synchronize需要的呼叫数
  • 小的
    • 几个文件:mmkv包含编码/解码助手和mmap逻辑,仅此而已。真的很整洁
    • 二进制大小小于30K:MMKV对每个架构的应用程序大小增加不到30K,压缩后(IPA)增加的更少

快速入门

通过CocoaPods安装:

  1. 安装CocoaPods
  2. 开放式终端,cd到您的项目目录,运行pod repo update使CocoaPods了解最新的MMKV版本;
  3. 编辑您的Podfile,添加pod 'MMKV'发送到您的应用程序目标;
  4. pod install
  5. 打开.xcworkspaceCocoaPods生成的文件;
  6. 添加#import <MMKV/MMKV.h>添加到您的源文件中,我们就完成了

有关其他安装选项,请参见iOS/macOS Setup

快速教程

你可以随时随地使用MMKV,不需要配置。所有更改都会立即保存,否synchronize需要打电话。在应用程序启动时设置MMKV,在您的-[MyApp application: didFinishLaunchingWithOptions:],添加以下行:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // init MMKV in the main thread
    [MMKV initializeMMKV:nil];

    //...
    return YES;
}

MMKV有一个全局实例,可以直接使用:

MMKV *mmkv = [MMKV defaultMMKV];
    
[mmkv setBool:YES forKey:@"bool"];
BOOL bValue = [mmkv getBoolForKey:@"bool"];
    
[mmkv setInt32:-1024 forKey:@"int32"];
int32_t iValue = [mmkv getInt32ForKey:@"int32"];
    
[mmkv setString:@"hello, mmkv" forKey:@"string"];
NSString *str = [mmkv getStringForKey:@"string"];

MMKV还支持多进程访问可以找到完整的教程here

性能

随机写入int对于10000次,我们得到了这个图表:

有关更多基准数据,请参阅our benchmark

适用于Win32的MMKV

功能

  • 高效MMKV使用mmap与文件保持内存同步,使用协议buf对值进行编码/解码,充分利用Windows实现最佳性能
    • 多进程并发:MMKV支持进程间并发读写访问
  • 易于使用你可以边走边用MMKV。所有更改都会立即保存,否save,否sync需要的呼叫数
  • 小的
    • 几个文件:MMKV包含进程锁、编码/解码助手和mmap逻辑等。真的很整洁
    • 二进制大小约为10K:MMKV增加了大约10K的应用程序大小,而压缩后的应用程序大小要少得多

快速入门

通过源安装

  1. 从GIT存储库获取源代码:
    git clone https://github.com/Tencent/MMKV.git
    
  2. 添加Win32/MMKV/MMKV.vcxproj您的解决方案;
  3. 添加MMKV项目到项目的依赖项;
  4. 添加$(OutDir)include到您的项目的C/C++->General->Additional Include Directories
  5. 添加$(OutDir)到您的项目的Linker->General->Additional Library Directories
  6. 添加MMKV.lib到您的项目的Linker->Input->Additional Dependencies
  7. 添加#include <MMKV/MMKV.h>添加到您的源文件中,我们就完成了

注:

  1. MMKV是用MT/MTd默认情况下运行时。如果您的项目使用MD/MDd,您应该更改MMKV的设置以匹配您的项目(C/C++->Code Generation->Runtime Library),或反之亦然
  2. MMKV是用Visual Studio 2017开发的,更改Platform Toolset如果使用不同版本的Visual Studio

有关其他安装选项,请参见Win32 Setup

快速教程

你可以边走边用MMKV。所有更改都会立即保存,否sync,否save需要的呼叫数
在应用程序启动时设置MMKV,例如在您的main(),添加以下行:

#include <MMKV/MMKV.h>

int main() {
    std::wstring rootDir = getYourAppDocumentDir();
    MMKV::initializeMMKV(rootDir);
    //...
}

MMKV有一个全局实例,可以直接使用:

auto mmkv = MMKV::defaultMMKV();

mmkv->set(true, "bool");
std::cout << "bool = " << mmkv->getBool("bool") << std::endl;

mmkv->set(1024, "int32");
std::cout << "int32 = " << mmkv->getInt32("int32") << std::endl;

mmkv->set("Hello, MMKV for Win32", "string");
std::string result;
mmkv->getString("string", result);
std::cout << "string = " << result << std::endl;

MMKV还支持多进程访问完整的教程可在此处找到Win32 Tutorial

用于POSIX的MMKV

功能

  • 高效MMKV使用mmap来保持内存与文件的同步,使用protocol buf来编解码值,充分利用POSIX来实现最佳性能
    • 多进程并发:MMKV支持进程间并发读写访问
  • 易于使用你可以边走边用MMKV。所有更改都会立即保存,否save,否sync需要的呼叫数
  • 小的
    • 几个文件:MMKV包含进程锁、编码/解码助手和mmap逻辑等。真的很整洁
    • 二进制大小约为7K:MMKV增加了大约7K的应用程序大小,而压缩后的大小要少得多

快速入门

通过CMake安装

  1. 从GIT存储库获取源代码:
    git clone https://github.com/Tencent/MMKV.git
    
  2. 编辑您的CMakeLists.txt,添加以下行:
    add_subdirectory(mmkv/POSIX/src mmkv)
    target_link_libraries(MyApp
        mmkv)
  3. 添加#include "MMKV.h"添加到您的源文件中,我们就完成了

有关其他安装选项,请参见POSIX Setup

快速教程

你可以边走边用MMKV。所有更改都会立即保存,否sync,否save需要的呼叫数
在应用程序启动时设置MMKV,例如在您的main(),添加以下行:

#include "MMKV.h"

int main() {
    std::string rootDir = getYourAppDocumentDir();
    MMKV::initializeMMKV(rootDir);
    //...
}

MMKV有一个全局实例,可以直接使用:

auto mmkv = MMKV::defaultMMKV();

mmkv->set(true, "bool");
std::cout << "bool = " << mmkv->getBool("bool") << std::endl;

mmkv->set(1024, "int32");
std::cout << "int32 = " << mmkv->getInt32("int32") << std::endl;

mmkv->set("Hello, MMKV for Win32", "string");
std::string result;
mmkv->getString("string", result);
std::cout << "string = " << result << std::endl;

MMKV还支持多进程访问完整的教程可在此处找到POSIX Tutorial

许可证

MMKV是在BSD 3条款许可下发布的。有关详细信息,请查看LICENSE.TXT

更改日志

请查看CHANGELOG.md有关更改历史的详细信息,请参阅

贡献

如果您对贡献感兴趣,请查看CONTRIBUTING.md,也加入我们的Tencent OpenSource Plan

为了明确对我们的成员的期望,MMKV通过了被广泛使用的贡献者公约定义的行为准则。我们认为它很好地表达了我们的价值观。有关更多信息,请查看Code of Conduct

常见问题和反馈

请查看FAQ第一。如果有任何问题,请不要犹豫issues

Kivy-用Python编写的开源UI框架,运行在Windows、Linux、MacOS、Android和iOS上

Kivy

创新的用户界面变得轻松

Kivy是一个开源的、跨平台的Python用于开发利用创新的多点触控用户界面的应用程序的框架。其目的是允许快速简单的交互设计和快速原型设计,同时使您的代码可重用和可部署

Kivy是用Python编写的,Cython,基于OpenGL ES 2,支持多种输入设备,具有丰富的微件库。使用相同的代码库,您可以针对Windows、MacOS、Linux、Android和iOS。所有Kivy小部件都支持多点触控

Kivy是麻省理工学院许可的,由一个伟大的社区积极开发,并得到由管理的许多项目的支持Kivy Organization

安装、文档和示例

详细的安装说明以及教程和一般文档(包括API参考)可在以下位置找到https://kivy.org/docs一个PDF version也是可用的

Kivy提供了许多示例,这些示例可以在examples文件夹

支持

如果您需要帮助,可以在我们的邮件列表上寻求帮助:

我们还有一个不和谐的频道:

贡献

我们喜欢提出请求和讨论新奇的想法。请查看我们的contribution guide你可以随意改进基维

以下邮件列表和不和谐频道专门用于讨论开发Kivy框架及其姊妹项目:

不和谐频道:

姊妹项目

  • Buildozer:Android和iOS通用Python打包程序
  • Plyer:平台相关API的平台无关Python包装器
  • Pyjnius:从Python动态访问Java/Android API
  • Pyobjus:从Python动态访问Objective-C/IOS API
  • Python for Android:用于为Android构建和打包Python应用程序的工具链
  • Kivy iOS:用于构建和打包适用于iOS的Kivy应用程序的工具链
  • Audiostream:用于直接访问麦克风和扬声器的库
  • KivEnt:面向Kivy的基于实体的游戏引擎
  • Garden:由用户创建和维护的小部件和库
  • Oscpy:OSC的一个快速且经过测试的python2/3实现

许可证

  • Kivy根据麻省理工学院的执照条款被释放。请参考许可证文件
  • 提供的字体Roboto和Roboto Mono根据Apache License, Version 2.0可以查看DejaVuSans(用于虚拟键盘)许可证here
  • 当前的UI设计改编自Moblintouch主题的SVG,并根据LGPLv2.1

贡献者

这个项目的存在要归功于所有做出贡献的人。[Contribute]

支持者

感谢我们所有的支持者!🙏[Become a backer]

赞助商

通过成为赞助商来支持这个项目。您的徽标将在此处显示,并带有指向您的网站的链接。[Become a sponsor]