【问题标题】:how include pandas library on my python package?如何在我的 python 包中包含 pandas 库?
【发布时间】:2012-08-27 00:24:35
【问题描述】:

我必须在我的包中包含 pandas 库才能在没有安装 pandas 库但具有所有正确依赖项的集群服务器上运行我的软件。

我尝试在我的电脑上从源代码(版本 0.8.1)构建 pandas 库:

python setup.py build_ext --inplace

如果我将构建的 pandas 文件夹移动到我电脑中其他文件夹中的任何位置,我可以将其导入我的软件(例如 ./mySoftwareFolder/pandas)

但是当我在集群服务器上使用 pandas libray 移动我的软件时,它会引发错误:

File "testPandas.py", line 9, in <module>
    import pandas
File "/home/TEST/pandas/__init__.py", line 15, in <module>

raise ImportError('C extensions not built: if you installed already '
ImportError: C extensions not built: if you installed already verify that you are not importing from the source directory

如果没有编译就好了。

我包含库的方式有什么问题?

非常感谢!

更新: 我复制到集群服务器的目录包含:

-bash-4.2$ ll -a pandas
totale 11476
drwxr-xr-x. 14 francesco dottor    4096  1 set 13.37 .
drwxr-xr-x. 10 francesco dottor    8192  1 set 13.36 ..
-rwxr-xr-x.  1 francesco dottor 2648299  1 set 13.36 _algos.so
drwxr-xr-x.  2 francesco dottor    4096  1 set 13.36 compat
drwxr-xr-x.  2 francesco dottor    4096  1 set 13.36 core
-rw-r--r--.  1 francesco dottor     394  1 set 13.36 info.py
-rw-r--r--.  1 francesco dottor     557  1 set 13.36 info.pyc
-rw-r--r--.  1 francesco dottor    1269  1 set 13.36 __init__.py
-rw-r--r--.  1 francesco dottor    1643  1 set 13.37 __init__.pyc
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 io
-rwxr-xr-x.  1 francesco dottor 7437108  1 set 13.36 lib.so
-rwxr-xr-x.  1 francesco dottor  474199  1 set 13.36 _period.so
drwxr-xr-x.  2 francesco dottor    4096  1 set 13.36 rpy
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 sandbox
-rw-r--r--.  1 francesco dottor     844  1 set 13.36 setup.py
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 sparse
-rwxr-xr-x.  1 francesco dottor 1065313  1 set 13.36 _sparse.so
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 src
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 stats
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 tests
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 tools
drwxr-xr-x.  3 francesco dottor    4096  1 set 13.36 tseries
drwxr-xr-x.  2 francesco dottor    4096  1 set 13.36 util
-rw-r--r--.  1 francesco dottor      42  1 set 13.36 version.py
-rw-r--r--.  1 francesco dottor     204  1 set 13.36 version.pyc

【问题讨论】:

  • 为什么不能安装:sudo apt-get install python-pandas?
  • 因为我不是集群服务器的管理员。而且我不明白为什么我的包中不能包含 pandas 的模块。
  • 不知道是不是和where python looks for the so file有关。

标签: import module pandas


【解决方案1】:

您在哪个平台上构建 C 扩展?在集群机器上,验证扩展共享对象(Linux/OSX 上的 .so 文件和 Windows 上的 .pyd 文件)是否在您复制的文件夹中:

08:21 ~/code/pandas/pandas  $ ll
total 12568
-rw-r--r--   1 wesm  staff     1269 Aug 25 04:49 __init__.py
-rw-r--r--   1 wesm  staff     1645 Aug 25 04:52 __init__.pyc
-rwxr-xr-x   1 wesm  staff   799464 Aug 25 04:50 _algos.so
-rwxr-xr-x   1 wesm  staff    65712 Aug 25 04:48 _engines.so
-rwxr-xr-x   1 wesm  staff   197056 Sep  1 22:13 _period.so
-rwxr-xr-x   1 wesm  staff   341032 Aug 25 04:53 _sparse.so
drwxr-xr-x   6 wesm  staff      204 Aug 25 04:52 compat
drwxr-xr-x  44 wesm  staff     1496 Sep  1 17:34 core
drwxr-xr-x   3 wesm  staff      102 Aug 25 04:49 finance
-rw-r--r--   1 wesm  staff      394 Aug 25 04:49 info.py
-rw-r--r--   1 wesm  staff      535 Aug 25 04:52 info.pyc
drwxr-xr-x  15 wesm  staff      510 Sep  1 23:14 io
-rwxr-xr-x   1 wesm  staff  2490600 Sep  1 22:13 lib.so
drwxr-xr-x   9 wesm  staff      306 Sep  1 17:34 rpy
drwxr-xr-x   6 wesm  staff      204 May 20 19:13 sandbox
-rw-r--r--   1 wesm  staff      844 Feb 22  2012 setup.py
drwxr-xr-x  17 wesm  staff      578 Aug 25 04:52 sparse
drwxr-xr-x  55 wesm  staff     1870 Sep  1 22:57 src
drwxr-xr-x  23 wesm  staff      782 Aug 25 04:52 stats
drwxr-xr-x  40 wesm  staff     1360 Sep  1 17:34 tests
drwxr-xr-x  16 wesm  staff      544 Aug 25 04:52 tools
drwxr-xr-x  28 wesm  staff      952 Sep  1 17:34 tseries
drwxr-xr-x  18 wesm  staff      612 Aug 25 04:52 util
-rw-r--r--   1 wesm  staff       54 Sep  1 22:57 version.py
-rw-r--r--   1 wesm  staff      204 Sep  1 22:58 version.pyc

【讨论】:

  • 嗨 Wes(我刚刚在 youtube 上查看了你的 pandas 教程,太棒了!!!)我使用 linux(ubuntu 12.04)编译 pandas 我复制到集群服务器的目录包含 .so 文件和我已经用文件列表更新了我的问题。
  • 我在 Eclipse 中使用 ubuntu 12.04 构建。得到与@Frank 相同的错误。我没有做任何花哨的事情,只是试图运行一个调用 pandas.io.parsers.read_csv 的 .py 。悬停提示显示“'C extensions not built: if you installed already '”。 $locate pandas 给出 /usr/lib/pymodules/python2.7/pandas/io/parsers.py /usr/lib/pymodules/python2.7/pandas/io/parsers.pyc 。在我的 pymodules 文件夹中,我有 _tseries.so、_engine.so、_sparse.so,但仅此而已。
  • 如果我改变对 pd.read_csv 的调用,错误就会消失(但我没有使用编译版本?)。我找到了 lib 设置(在 windows->preferences->python->interpreter no project->properties!)pasteall.org/pic/show.php?id=37312 并添加了 /usr/lib/pymodules/python2.7/pandas 但这并没有解决它。
猜你喜欢
  • 2014-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-25
  • 2017-11-19
  • 2016-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多