本文介绍了statsmodels ImportError中的python 3.5:无法导入名称"_representation"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行此操作时,我无法正确导入statsmodels.api:

I cannot manage to import statsmodels.api correctly when i do that I have this error:

我已经尝试重新安装或更新它,但不会改变.请帮助我=)

I already try to re-install or update it, that does not change.plese i need help =)

推荐答案

请参阅 github报告了解更多信息.

事实证明statsmodels依赖于安装之前的几个软件包,因此它可以依靠它们来编译自己的模块.我不完全理解这些依赖关系,或者为什么不在软件包的设置中指定它们,但这为我解决了这个问题.

It turns out that statsmodels is dependent upon several packages being installed before it so that it can key on them to compile its own modules. I don't completely understand the dependencies, or why they aren't specified in the package's setup, but this solves the problem for me.

如果需要清理已有的内容,可以使用以下方法卸载:

If you need to clean out what you already have, you can uninstall with the following:

pip3 uninstall statsmodels

然后确保您的依赖项在那里

then make sure your dependencies are there

pip3 install numpy scipy patsy pandas

然后,仅在首先安装这四个之后:

then, only after these four are installed first:

pip3 install statsmodels

然后继续导入和输入代码.

Then move on with your imports and code.

====另外/交替=====

==== additionally / alternately =====

在大多数情况下,建议使用 virtualenv .它还将允许您创建自己的环境,在其中可以控制自己的库.您可以创建所需的所有内容,并为每个项目随意命名.您现在可能混合使用了在系统级别和用户级别安装的python模块,并且在更新系统软件包时,它们可能会从您的下方更改.您的系统版本的scipy可能与较新的statsmodels用户版本相冲突.对于python 3.5,您必须安装venv;但是在3.6版本中,它成为了分布的一部分.

It is recommended to use virtualenv in most cases. It also would allow you to create your own environments where you can control your own libraries. You can create all you want, and name them whatever you like for each project. It is likely that you are now using a mix of python modules installed at the system level and the user level, and they could change out from under you when the system packages are updated. It's possible you have a system version of scipy that conflicts with a newer user version of statsmodels. For python 3.5, you have to install venv; but with 3.6 it becomes part of the distribution.

首先,从刚运行python3时开始查看系统路径.

First, look at your system paths from when you just run python3.

python3
>>> import sys
>>> print(sys.path)
>>> quit()

然后创建一个干净的独立环境,并执行相同的操作.

And then create a clean, independent environment and do the same.

sudo apt install python3-venv
python3 -m venv ~/name_me
source ~/name_me/bin/activate
python3
>>> import sys
>>> print(sys.path)
>>> quit()

它应该具有指向基本库的路径,但应避免指向已安装的其他软件包的路径.您有一个干净的环境可将它们安装到其中.然后,在该virtualenv中,应该可以通过更改后的shell提示检测到该环境,您可以从之前进行pip安装,并查看它们是否有效.

It should have paths to base libaries, but avoid paths to the installed additional packages. You have a clean environment to install them into. Then, from within this virtualenv, which you should be able to detect by your changed shell prompt, you can do the pip installs from before and see if they work.

pip install numpy scipy patsy pandas
pip install statsmodels
python
>>> import statsmodels.api as sm

完成后,您可以退出virtualenv

And when you are done, you can exit the virtualenv

deactivate

这篇关于statsmodels ImportError中的python 3.5:无法导入名称"_representation"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:04