如何在不安装 numpy 的情况下使用它?

发布于 2024-11-28 21:48:27 字数 1633 浏览 1 评论 0 原文

我通过控制台访问没有 root 或 sudo 权限的计算机。

Python版本是2.5.2,numpy不可用。我无法使用 python setup.py install --user ,机器上也没有任何可用的编译器。

我可以以某种方式使用可用的编译包 https://edge.launchpad.net/ ~scipy/+archive/ppa/+packages 而不安装它们?我尝试直接导入 numpy 模块,但它抱怨:

Python 2.5.2 (r252:60911, Jan  4 2009, 21:59:32)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/home/XXX/temp/python-numpy-1.2.1/numpy/__init__.py", line 121,
 in <module>
    raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python intepreter from there.
>>>

谢谢!

更新: 系统管理员不会在计算机中安装任何类型的软件(这是一个 VPS,我的猜测是他们有一个用于部署的标准映像)。他们疯狂偏执,他们甚至不告诉我他们正在运行什么风格的unix,甚至Apache服务的版本号也被混淆了!这是我在登录时获得的所有信息:

Linux server1 2.4.22 #4 SMP Wed Nov 5 17:44:16 CET 2003 i686 unknown

用于编译:

python setup.py install --home=~
[...]
RuntimeError: Broken toolchain: cannot link a simple C program

cat /proc/version

Linux version 2.6.32.25-grsec-dh ([email protected]) (gcc version 4.3.2
(Debian 4.3.2-1.1) ) #2 SMP Wed Nov 3 13:21:01 CET 2010

I console access to a computer where I do not have root nor sudo rights.

Python version is 2.5.2 and numpy is not available. I cannot use python setup.py install --user nor there are any compilers available on the machine.

Can I somehow use the compiled packages available https://edge.launchpad.net/~scipy/+archive/ppa/+packages without installing them? I tried importing the numpy module directly but it complains:

Python 2.5.2 (r252:60911, Jan  4 2009, 21:59:32)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/home/XXX/temp/python-numpy-1.2.1/numpy/__init__.py", line 121,
 in <module>
    raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python intepreter from there.
>>>

Thanks!

Update:
The sysadmin will not install any kind of software in the machine (it's a VPS and my guess is that they have a standard image for deployment). They are crazy paranoic, they won't even tell me what flavor of unix they are running, and even the Apache service has the version number obfuscated! This is all the information I get upon login:

Linux server1 2.4.22 #4 SMP Wed Nov 5 17:44:16 CET 2003 i686 unknown

And for compiling:

python setup.py install --home=~
[...]
RuntimeError: Broken toolchain: cannot link a simple C program

cat /proc/version

Linux version 2.6.32.25-grsec-dh ([email protected]) (gcc version 4.3.2
(Debian 4.3.2-1.1) ) #2 SMP Wed Nov 3 13:21:01 CET 2010

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无远思近则忧 2024-12-05 21:48:27

如果您可以解决所有依赖项,您可能可以使用dpkg将其安装在您的$HOME中。 dpkg 不会自动解析依赖项,因此您可能必须确定安装软件包的正确顺序。下载您感兴趣的 .deb 文件,并对每个软件包运行以下命令:

$ dpkg -i --force-not-root --root=$HOME mypackagename.deb

如果您随后将新安装的 Numpy 的目录添加到 $PYTHONPATH 或 sys.path 中,Numpy 可能会正常工作。

或者,您可以从 Numpy 的其他二进制发行版之一(例如 Sage)中提取所需的文件。

Numpy 对于它需要的依赖项版本非常挑剔,因此您最好下载适用于您正在使用的特定 Linux 版本的软件包。

最后,考虑询问您的管理员是否会为您安装 Numpy。您会惊讶地发现一个简单的请求经常可以解决您的所有问题,特别是因为它只是一个 apt-get 命令。

编辑:作为替代方案,如果您可以访问另一台运行相同版本/架构的 Ubuntu/Debian 的计算机,您也许可以下载 numpy 源 tarball,使用 python 进行编译setup.py build 然后只需复制 directory_where_you_extracted_the_tarball/build/numpy/lib.OS-arch-PythonVersion 中的所有内容(在我的系统上,它是lib.linux-x86_64-2.6/) 到您在目标计算机上选择的目录。然后,只需将该目录添加到 $PYTHONPATH 中即可。请记住复制内容,而不是整个目录(tar -jcf np.tar.bz2 /path/to/numpy/build/numpy/lib.OS-arch-PythonVersion/numpy 然后获取 tar .bz2 到远程计算机并将其解压到您选择的目录中)。

这里有一些关于如何使用 setuptools 的文档:http://docs。 python.org/install/index.html#how-installation-works

手动构建 Numpy 并不适合胆小的人,所以这可能会导致很多头撞和头发撕裂。

If you can resolve all the dependencies, you might be able to install it in your $HOME using dpkg. dpkg doesn't resolve dependencies automatically, so you might have to figure out the right order to install the packages in. Download the .deb files that you're interested in and run the following command for each package:

$ dpkg -i --force-not-root --root=$HOME mypackagename.deb

If you then add the directory with the newly installed Numpy to your $PYTHONPATH, or to sys.path, Numpy might just work.

Alternatively, you might be able to extract the files you need from one of the other binary distributions of Numpy around (such as Sage).

Numpy is quite fussy about what versions of its dependencies it requires though, so you're probably best off downloading the packages for the specific version of Linux that you're using.

Finally, consider asking your administrator whether s/he'll install Numpy for you. You'd be surprised how often a simple request can solve all your problems, especially since it's just one apt-get command.

EDIT: Just as an alternative, if you can get access to another machine running the same version/architecture of Ubuntu/Debian, you might be able to download the numpy source tarball, compile with python setup.py build and then just copy everything in directory_where_you_extracted_the_tarball/build/numpy/lib.OS-arch-PythonVersion (on my system, it is lib.linux-x86_64-2.6/) to a directory of your choice on the target machine. Then, just add that directory to your $PYTHONPATH and you're done. Remember to copy the contents, not the whole directory (tar -jcf np.tar.bz2 /path/to/numpy/build/numpy/lib.OS-arch-PythonVersion/numpy then get the tar.bz2 to the remote machine and extract it in a directory of your choice).

There is some documentation on how to use setuptools here: http://docs.python.org/install/index.html#how-installation-works

Building Numpy by hand is not for the faint of heart though, so this might lead to a lot of head-banging and hair-tearing.

梦初启 2024-12-05 21:48:27

我不是 100% 这会起作用,但是 Enthought 有一个免费版本的 EPD,其中包含 numpy 和 scipy,可能不需要安装编译器(因为据我所知,它只是安装二进制文件),并且不不需要 root 访问权限:

http://www.enthought.com/products/epd_free.php

I'm not 100% this will work, but Enthought has a free version of the EPD that has numpy and scipy included, that may not require a compiler to install (since it's just installing binaries as far as I can tell), and doesn't need root access:

http://www.enthought.com/products/epd_free.php

蒲公英的约定 2024-12-05 21:48:27

您可以尝试在具有相似架构的类似计算机上设置 virtualenv 环境。然后在 VPS 计算机上本地安装 virtualenv 并尝试将环境复制到那里。

You could try setting up a virtualenv environment on a similar machine with similar architecture. Then install virtualenv locally on the VPS machine and try copying the environment there.

蓝颜夕 2024-12-05 21:48:27

您可以使用 python 的 distutils (这是 python setup.py 运行的)安装到本地目录,必须将其添加到您的 PYTHONPATH。 EG,

python setup.py install --prefix=~/local

它使用目录层次结构~/local/lib/python2.x。 (或者您可以使用 --home=

来避免 python2.x 部分)

You can use python's distutils (which is what python setup.py runs) install to a local directory, which must be added to your PYTHONPATH. E.G.,

python setup.py install --prefix=~/local

which uses a directory hierarchy ~/local/lib/python2.x. (Or you can use --home=<dir> to avoid the python2.x part)

梨涡 2024-12-05 21:48:27

与基于 setup.py 或 pip 的方法不同,通过 conda 安装 Numpy 不需要访问任何编译器。

  1. 安装某种形式的 conda。我建议使用 mambaforge

    curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
    bash Mambaforge-$(uname)-$(uname -m).sh
    
  2. 使用 conda/mamba/micromamba 将 Numpy 从 conda-forge 通道安装到名为的新 conda 环境中my_env

    mamba create -n my_env -c conda-forge numpy
    
  3. 激活 conda 环境:

    mamba activate -n my_env
    
  4. 安装了 numpy 运行 python:

    <前><代码>Python

Unlike the setup.py or pip-based methods, installing Numpy via conda does not require having access to any compilers.

  1. Install some form of conda. I'll suggest using mambaforge:

    curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
    bash Mambaforge-$(uname)-$(uname -m).sh
    
  2. Use conda/mamba/micromamba to install Numpy from the conda-forge channel into a new conda environment named my_env:

    mamba create -n my_env -c conda-forge numpy
    
  3. Activate the conda environment:

    mamba activate -n my_env
    
  4. Run python with numpy installed:

    python
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文