Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误:找不到vcvarsall.bat_Python_Windows_Pip_Setup.py_Failed Installation - Fatal编程技术网

Python 错误:找不到vcvarsall.bat

Python 错误:找不到vcvarsall.bat,python,windows,pip,setup.py,failed-installation,Python,Windows,Pip,Setup.py,Failed Installation,我尝试安装Python软件包: pip安装德威治 但我得到一个神秘的错误信息: 错误:找不到vcvarsall.bat 如果我尝试手动安装软件包,也会发生同样的情况: python setup.py安装 运行build_ext 建筑“德威治对象”扩建部分 错误:找不到vcvarsall.bat 看起来像是在寻找VC编译器,所以您可以尝试使用-c mingw32提及编译器类型,因为您有msys python setup.py install -c mingw32 我找到了解决办法。 安装“a

我尝试安装Python软件包:

pip安装德威治
但我得到一个神秘的错误信息:

错误:找不到vcvarsall.bat
如果我尝试手动安装软件包,也会发生同样的情况:

python setup.py安装 运行build_ext 建筑“德威治对象”扩建部分 错误:找不到vcvarsall.bat
看起来像是在寻找VC编译器,所以您可以尝试使用
-c mingw32
提及编译器类型,因为您有msys

python setup.py install -c mingw32
我找到了解决办法。 安装“amara”时,我遇到了完全相同的问题和错误。我已经安装了mingw32,但是需要配置distutils

  • 我已经安装了Python 2.6
  • 我将mingw32安装到
    C:\programs\mingw\
  • 将mingw32的bin目录添加到环境变量:append
    c:\programs\MinGW\bin路径
  • 将位于
    C:\Python26\Lib\distutils\distutils.cfg
    的文件编辑(如果不存在则创建)distutils.cfg为:

    [build]
    compiler=mingw32
    
  • 现在运行
    easy\u install.exe amara


  • 通过打开一个新的
    cmd.exe

    确保环境已设置。您可以从安装编译版本,我刚刚遇到了同样的问题,因此我将在这里讲述我的故事,希望它能帮助其他人解决同样的问题,并为他们节省我刚刚花费的几个小时:

    我在Windows7中安装了mingw(g++(GCC)4.6.1)和Python2.7.3,我正在尝试安装PyCrypto

    在运行setup.py安装时,这一切都是由以下错误开始的:

    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\cygwingcompiler.py,以删除-mno-cygwin的所有实例。”

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

    更新:评论指出这里的说明可能很危险。考虑使用Visual C++ 2008 Express版本或目的生成的()和<强>不<强>使用下面的原始答案。原始错误消息意味着未安装VisualC++的必需版本。
    对于Windows安装:

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

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

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

    警告:如下所述,如果您试图编译python模块,这个答案不太可能起作用


    有关详细信息,请参阅。

    我有python 2.73和windows 7。适合我的解决方案是:

  • 将mingw32的bin目录添加到环境变量中:使用
    C:\programs\mingw\bin追加PATH
  • 创建的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))
    

    也许有人会感兴趣,以下是我为py2exe软件包所做的工作。 (我有windows 7 64位和便携式python 2.7、Visual Studio 2005 Express和windows SDK for windows 7和.NET Framework 4)

    然后:


    如果要在未安装Visual Studio的Windows设备上安装pyodbc,另一个选项是使用二进制发行版手动安装pyodbc

    如果您在正在使用的计算机上没有管理员权限,并且正在尝试设置一个管理员权限,则这一点特别有用

    步骤:

  • 从(pyodbc-X.X.X.win-Y-py2.7.exe)下载最新的Windows安装程序
  • 使用7-Zip(或WinRAR或其他任何工具)打开安装程序可执行文件
  • 提取pyodbc.pyd和pyodbc-X.X.X-py2.7.egg-info并将它们放置在
    [python安装目录或virtualenv]\Lib\site包中
  • 没有步骤4:)

  • 我尝试了上述所有答案,发现所有答案都不起作用,这可能是因为我使用的是Windows 8,并且安装了Visual Studio 2012。在这种情况下,这就是你要做的

    vcvvarsall.bat
    文件位于此处:
    C:\ProgramFiles(x86)\Microsoft Visual Studio 11.0\VC

    只需选择文件,然后复制它

    然后转到以下目录:
    C:\ProgramFiles(x86)\Microsoft Visual Studio 11.0\Common7\Tools


    然后粘贴文件。然后,所有的都应该是好的。

    < P>我尝试了很多解决方案,但是只有一个对我有用,微软Visual Studio的安装<强> 2008 < /强> Express C++ > < /P> 我在用C编写的Python2.7模块中遇到了这个问题(yEnc,它在MS VS中还有其他问题)。请注意,Python2.7是使用MS VS 2008版本而不是2010版本构建的

    尽管它是免费的,但很难找到,因为微软正在推广VS2010。
    尽管如此,MSDN官方的非常直接的链接仍然有效:检查下载链接。

    由@monkey给出的答案是正确的,但它是不完整的

    如果你想使用,你应该选择C,C++和其他开发

    set VS90COMNTOOLS=%VS80COMNTOOLS%
    
    python.exe setup.py install
    
    [build]
    compiler=mingw32
    
    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)   
    
    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
    
    pip install --global-option build_ext --global-option --compiler=mingw32 packagename
    
    C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
    
    C:/Python27/lib/distutils
    
    productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
    
    productdir = os.path.join(toolsdir)
    
    > iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
    > choco install python2 -y
    > choco install vcpython27 -y
    
    # 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()
    
    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