为什么Conda在我的环境之外使用python软件包?

时间:2018-09-23 07:30:35

标签: python package anaconda conda

我刚刚使用python 3.5.6版创建了一个新的conda环境。我安装了一个名为zipline的软件包,一切正常。我激活了环境,看起来还可以。当我运行一些测试代码时,我得到一个错误,它试图使用依赖项(numpy)并将其在我的新环境之外。它使用MacOSX计算机上默认python安装的numpy代码,它是python 2.7版本。这让我很烦恼。为什么要查看当前环境中未安装的任何软件包?所以我想我只需要在我的python 3.5 env中安装新版本的numpy。但是当我尝试这样做时,conda告诉我所有的依赖关系都已经满足。

这是错误。您可以看到第一行,它是导入我在新环境中安装的新软件包。然后它试图获取numpy,并寻找一个python 2.7文件夹。从我的角度来看,当我的环境激活时,似乎永远都不要在那个2.7文件夹中查找。我从未安装过numpy,因此似乎应该说找不到模块。

Traceback (most recent call last):
  File "markowitz.py", line 1, in <module>
    from zipline.utils.factory import load_bars_from_yahoo
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/site-packages/zipline/__init__.py", line 17, in <module>
    import numpy as np
  File "/Users/apple/anaconda/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/Users/apple/anaconda/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/Users/apple/anaconda/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/Users/apple/anaconda/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/Users/apple/anaconda/lib/python2.7/site-packages/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

好的,所以我尝试了一些。我退出了环境,并从conda卸载了numpy。我注意到在新环境中仍然有适用于python 3.5的numpy版本。这样很好。我从新的env内部重新运行了脚本,但没有得到相同的错误,但是另一个试图从默认python 2.7安装中引用的软件包却出现了错误。所以它是相同类型的错误。为什么这样做呢?似乎是在默认的conda软件包中查找,然后才在env中查找这些软件包?

这是新错误:

Traceback (most recent call last):
  File "markowitz.py", line 1, in <module>
    from zipline.utils.factory import load_bars_from_yahoo
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/site-packages/zipline/__init__.py", line 21, in <module>
    from trading_calendars import get_calendar
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/site-packages/trading_calendars/__init__.py", line 16, in <module>
    from .trading_calendar import TradingCalendar
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/site-packages/trading_calendars/trading_calendar.py", line 20, in <module>
    from pandas.tseries.holiday import AbstractHolidayCalendar
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/site-packages/pandas/__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/site-packages/pandas/compat/__init__.py", line 34, in <module>
    import platform
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/platform.py", line 117, in <module>
    import sys, os, re, subprocess
  File "/Users/apple/anaconda/envs/env_zipline_p36/lib/python3.5/subprocess.py", line 127, in <module>
    import _posixsubprocess
ImportError: dlopen(/Users/apple/anaconda/lib/python2.7/site-packages/_posixsubprocess.so, 2): Symbol not found: _PyString_AsString
  Referenced from: /Users/apple/anaconda/lib/python2.7/site-packages/_posixsubprocess.so
  Expected in: flat namespace
 in /Users/apple/anaconda/lib/python2.7/site-packages/_posixsubprocess.so

0 个答案:

没有答案