Python pip 无法定位 pyodbc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21054656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:55:55  来源:igfitidea点击:

Python pip unable to locate pyodbc

pythonpippyodbc

提问by ely

Using virtualenv and just trying to install pyodbc. All resources I can find claim this should be extremely straightforward. After all the basic installs of MySQL, etc., just do:

使用 virtualenv 并尝试安装 pyodbc。我能找到的所有资源都声称这应该非常简单。在 MySQL 等所有基本安装之后,只需执行以下操作:

pip install pyodbc

However, I am seeing a very strange error. It has nothing (as far as I can tell) to do with missing libraries, and after Googling for this sort of error for a long time, I can't find anything constructive on it at all.

但是,我看到了一个非常奇怪的错误。它与丢失的库没有任何关系(据我所知),在谷歌搜索这种错误很长时间之后,我根本找不到任何建设性的东西。

(local-dev)espears@espears-w ~ $ pip install pyodbc
Downloading/unpacking pyodbc
  Could not find any downloads that satisfy the requirement pyodbc
  Some externally hosted files were ignored (use --allow-external pyodbc to allow).
Cleaning up...
No distributions at all found for pyodbc
Storing debug log for failure in /home/espears/.pip/pip.log

So I tried with the "allow-external" option and it does not help:

所以我尝试了“允许外部”选项,但它没有帮助:

(local-dev)espears@espears-w ~ $ pip install --allow-external pyodbc
You must give at least one requirement to install (see "pip help install")

But the help documentation makes it appear that I am using this option correctly, e.g. from the output of running pip help install:

但是帮助文档表明我正确使用了这个选项,例如从 running 的输出中pip help install

Package Index Options:

...

  --allow-external <package>  Allow the installation of externally hosted files

Here's the result in the PIP log file:

这是 PIP 日志文件中的结果:

(local-dev)espears@espears-w ~ $ cat /home/espears/.pip/pip.log
Downloading/unpacking pyodbc
  Getting page https://pypi.python.org/simple/pyodbc/
  URLs to search for versions for pyodbc:
  * https://pypi.python.org/simple/pyodbc/
  Analyzing links from page https://pypi.python.org/simple/pyodbc/
    Skipping link http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/); not a file
    Skipping link http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/); not a file
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Not searching http://code.google.com/p/pyodbc/downloads/list (from https://pypi.python.org/simple/pyodbc/) for files because external urls are disallowed.
  Could not find any downloads that satisfy the requirement pyodbc
  Some externally hosted files were ignored (use --allow-external pyodbc to allow).
Cleaning up...
  Removing temporary dir /home/espears/.virtualenvs/local-dev/build...
No distributions at all found for pyodbc
Exception information:
Traceback (most recent call last):
  File "/home/espears/.virtualenvs/local-dev/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/home/espears/.virtualenvs/local-dev/local/lib/python2.7/site-packages/pip/commands/install.py", line 270, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/home/espears/.virtualenvs/local-dev/local/lib/python2.7/site-packages/pip/req.py", line 1157, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/home/espears/.virtualenvs/local-dev/local/lib/python2.7/site-packages/pip/index.py", line 285, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for pyodbc

It makes it seem that if I can just get the --allow-externaloption to work, it will work because it clearly sees the common location for getting pyodbc.

看起来,如果我可以--allow-external选择工作,它就会起作用,因为它清楚地看到了获取 pyodbc 的常见位置。

But I am puzzled why this is needed at all, when virtually all references to installing pyodbc do not need to go out of the way to enable external links. I've also been installing many packages all day today, with few issues and certainly not encountering this allow-externalneed in any other case.

但我很困惑为什么需要这样做,因为几乎所有安装 pyodbc 的参考都不需要特意启用外部链接。我今天也一整天都在安装许多软件包,几乎没有问题,而且allow-external在任何其他情况下肯定不会遇到这种需求。

I am using pip version 1.5 with Python 2.7.3 on Ubuntu 12.04.

我在 Ubuntu 12.04 上使用 pip 1.5 版和 Python 2.7.3。

采纳答案by sholsapp

Running pip install --allow-external pyodbc --allow-unverified pyodbc pyodbcwill work if the PyPI directory structure is correct.

pip install --allow-external pyodbc --allow-unverified pyodbc pyodbc如果 PyPI 目录结构正确,运行将起作用。

Based on the pip.log output when I originally posted this answer, I think that package's website directory structure was broken. You can always work around this type of problem by specifying the URL of the package like pip install https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/pyodbc/pyodbc-3.0.7.zip, links for different versions are described here.

根据我最初发布此答案时的 pip.log 输出,我认为该包的网站目录结构已损坏。您始终可以通过指定包的 URL 来解决此类问题,例如此处pip install https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/pyodbc/pyodbc-3.0.7.zip描述了不同版本的链接。

回答by Bowie Owens

I just tried installing pyodbc as well and hit the same wall. I think the problem you and I both hit is that --allow-external consumes the next argument as well. So you actually need to write:

我也只是尝试安装 pyodbc 并撞到了同一堵墙。我认为你和我都遇到的问题是 --allow-external 也消耗了下一个参数。所以你实际上需要写:

sudo pip install --allow-external pyodbc pyodbc

I then hit another error about unverified sources so that command that actually worked for me was:

然后,我遇到了另一个关于未经验证的来源的错误,因此对我实际有用的命令是:

sudo pip install --allow-external pyodbc --allow-unverified pyodbc pyodbc

Note that once that was done the permissions on the installed files prevented normal users from access pyodbc. So I went in manually adjusted the permissions on all installed packages (seemed easier than finding just the files needed by pyodbc).

请注意,一旦完成,对已安装文件的权限会阻止普通用户访问 pyodbc。所以我手动调整了所有已安装包的权限(似乎比只找到 pyodbc 需要的文件更容易)。

cd /usr/local/lib/python2.7/
chmod -R o=g dist-packages

As per the suggestion of EMS I have added an issue to the Pip bug tracker. It can be found at:

根据 EMS 的建议,我在 Pip 错误跟踪器中添加了一个问题。它可以在以下位置找到:

https://github.com/pypa/pip/issues/1893

https://github.com/pypa/pip/issues/1893

回答by joefromct

FWIW, on ms windows anything other than installing the binary (windows install) for me was cumbersome in a windows/cygwin hybrid environment.

FWIW,在 ms windows 上,除了为我安装二进制文件(windows install)之外,在 windows/cygwin 混合环境中,其他任何事情都很麻烦。

I opted to use pypyodbcas it's pure python and didn't require any changes for my windows/linux development. It can be seen as an almost drop-in replacement for pyodbcwith no compilation needed, and of course can be installed easily with pip install pypyodbc.

我选择使用pypyodbc,因为它是纯 python 并且不需要对我的 windows/linux 开发进行任何更改。它几乎可以被看作是pyodbc 的替代品,无需编译,当然也可以使用pip install pypyodbc.

回答by jvh

There is an "easier" way to install pyodbc on windows in a virualenv using easy_install:

使用easy_install在 virualenv 中的 windows 上安装 pyodbc 有一种“更简单”的方法:

  • download latest pyodbc installer for windows
  • activate your virtualenv
  • easy_install pyodbc-3.0.7.win32-py2.7.exe

  • 下载适用于 Windows 的最新 pyodbc 安装程序
  • 激活你的虚拟环境
  • easy_install pyodbc-3.0.7.win32-py2.7.exe

as used for pywin32 see: How can I use pywin32 with a virtualenv without having to include the host environment's site-packages folder?

如用于 pywin32,请参阅:如何将 pywin32 与 virtualenv 一起使用,而不必包含主机环境的 site-packages 文件夹?

回答by Carl Ekerot

I had success when installed with

安装时我成功了

sudo pip install --allow-external pyodbc --allow-unverified pyodbc pyodbc

However, I also needed the unixodbc-devpackage in order for pyodbc to actually compile.

但是,我还需要该unixodbc-dev包才能实际编译 pyodbc。

回答by Kashyap

Both --allow-unverifiedand --allow-externaltake package name as an argument.

双方--allow-unverified--allow-external采取包名作为参数。

From pip help install:
--allow-external <package>   Allow the installation of a package even if it
                             is externally hosted
--allow-unverified <package> Allow the installation of a package even if it 
                             is hosted in an insecure and unverifiable way
  • --allow-externalrequires an argument (name of th external to allow).
  • Same goes for --allow-unverifiedtoo .
  • With pip install --allow-external pyodbc, you are allowing the external called pyodbc
  • pip install --allow-external pyodbc pydodbcis what you need, first pyodbcallows that external, second one actually tells pip which package to install.

    From pip help install: --allow-external Allow the installation of a package even if it is externally hosted --allow-unverified Allow the installation of a package even if it is hosted in an insecure and unverifiable way

  • --allow-external需要一个参数(允许的外部名称)。
  • 也一样--allow-unverified
  • 使用pip install --allow-external pyodbc,您允许外部调用pyodbc
  • pip install --allow-external pyodbc pydodbc是你需要的,首先pyodbc允许外部,第二个实际上告诉 pip 要安装哪个包。

    从 pip help install: --allow-external 允许安装包,即使它是外部托管的 --allow-unverified 允许安装包,即使它以不安全和无法验证的方式托管

So your usage should be

所以你的用法应该是

pip install <pkg> --allow-unverified <pkg> --allow-external <pkg>

pip install <pkg> --allow-unverified <pkg> --allow-external <pkg>

or the little confusing:

或有点令人困惑:

pip install --allow-unverified <pkg> --allow-external <pkg> <pkg>

pip install --allow-unverified <pkg> --allow-external <pkg> <pkg>

DO NOTuse --allow-all-externalwhen you just want to allow one and not ALL. It kills the whole purpose of putting in the security check.

--allow-all-external当您只想允许一个而不是ALL时,请勿使用。它扼杀了进行安全检查的全部目的。