我通过控制台访问没有 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
发布评论
评论(5)
如果您可以解决所有依赖项,您可能可以使用
dpkg
将其安装在您的$HOME中。dpkg
不会自动解析依赖项,因此您可能必须确定安装软件包的正确顺序。下载您感兴趣的 .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: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 indirectory_where_you_extracted_the_tarball/build/numpy/lib.OS-arch-PythonVersion
(on my system, it islib.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.
我不是 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
您可以尝试在具有相似架构的类似计算机上设置 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.
您可以使用 python 的
distutils
(这是python setup.py
运行的)安装到本地目录,必须将其添加到您的 PYTHONPATH。 EG,它使用目录层次结构
~/local/lib/python2.x
。 (或者您可以使用--home=
来避免
python2.x
部分)You can use python's
distutils
(which is whatpython setup.py
runs) install to a local directory, which must be added to your PYTHONPATH. E.G.,which uses a directory hierarchy
~/local/lib/python2.x
. (Or you can use--home=<dir>
to avoid thepython2.x
part)与基于 setup.py 或 pip 的方法不同,通过 conda 安装 Numpy 不需要访问任何编译器。
安装某种形式的 conda。我建议使用 mambaforge:
使用
conda
/mamba
/micromamba
将 Numpy 从conda-forge
通道安装到名为的新 conda 环境中my_env
:激活 conda 环境:
安装了 numpy 运行 python:
<前><代码>Python
Unlike the
setup.py
orpip
-based methods, installing Numpy via conda does not require having access to any compilers.Install some form of conda. I'll suggest using mambaforge:
Use
conda
/mamba
/micromamba
to install Numpy from theconda-forge
channel into a new conda environment namedmy_env
:Activate the conda environment:
Run python with numpy installed: