简体   繁体   English

如何在python3库中安装xlrd

[英]How to install xlrd in python3 library

I am trying to install xlrd to read Excel files in python.我正在尝试安装 xlrd 以在 python 中读取 Excel 文件。

I have tried this: pip install -U pip setuptools.我试过这个:pip install -U pip setuptools。 My macOS Mojave 10.4.3 has Python 2.7 which is where the default install goes to.我的 macOS Mojave 10.4.3 有 Python 2.7,这是默认安装的位置。 But I have also installed Python3.7.但是我也安装了Python3.7。 How do I get pip install to my 3.7 directory?如何将 pip install 安装到我的 3.7 目录?

I am on Mac machine(Catalina -version 10.15.5) and below pip3 command worked for me.我在 Mac 机器上(Catalina -version 10.15.5),下面的 pip3 命令对我有用。

pip3 install xlrd

python version : 3.7.6蟒蛇版本:3.7.6

OS : Mac-Catalina(10.15.5)操作系统:Mac-Catalina(10.15.5)

Thanks to @Tapan Hegde , pip3 install xlrd worked from me, after installing the pip3, like this:感谢@Tapan Hegde ,在安装 pip3 之后, pip3 install xlrd对我有用,如下所示:

sudo apt update

apt install python3-pip

pip3 install xlrd

I reckon the easiest/cleanest solution would be to use a tool that isolates your python environment, such as virtualenv我认为最简单/最干净的解决方案是使用隔离您的 python 环境的工具,例如virtualenv

Once installed, create a virtual env by specifying which version of python you want to use:安装后,通过指定要使用的 python 版本来创建一个虚拟环境:

$> virtualenv -p python3 env

Note: puttin python3 directly works only for mac, with linux, you must specify the absolute path or your python binary.注意:puttin python3直接只适用于mac,使用linux,你必须指定绝对路径或者你的python二进制文件。

And then 'activate' your environment:然后“激活”你的环境:

$> source env/bin/activate

From here, any python or pip command you use will use python3.从这里开始,您使用的任何 python 或 pip 命令都将使用 python3。

$> pip install xlrd

Virtualenv has the advantage of not 'polluting' your local python installation, your can manage your pip modules installed more easily. Virtualenv 的优点是不会“污染”您的本地 python 安装,您可以更轻松地管理安装的 pip 模块。

If you want more detail on how it works and the other alternatives, check this post如果您想了解有关其工作原理和其他替代方案的更多详细信息,请查看此帖子

When pip install xlrd not work and in computer is still old version, then try do it with current version, for example pip install xlrd==2.0.1 .pip install xlrd不起作用并且计算机中仍然是旧版本时,请尝试使用当前版本进行操作,例如pip install xlrd==2.0.1 The current versions are here当前版本在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM