Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use numpy without installing it?

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
like image 206
Josep Valls Avatar asked Aug 07 '11 23:08

Josep Valls


People also ask

Does NumPy need to be downloaded?

If you installed the Anaconda distribution of Python, NumPy comes pre-installed and no further installation steps are necessary. If you use a version of Python from python.org or a version of Python that came with your operating system, the Anaconda Prompt and conda or pip can be used to install NumPy.

Do I have to install NumPy everytime?

Depends. Your first numpy module likely installed in a virtual environment. Therefore, unless you specify that same virtual environment for your new project, your new project will be unable to access a module installed in a virtual environment it doesn't use.

Do you have to pip install NumPy?

The only thing that you need for installing Numpy on Windows are: Python. PIP or Conda (depending upon user preference)

Why does my Python not have NumPy?

The Python "ModuleNotFoundError: No module named 'numpy'" occurs when we forget to install the numpy module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install numpy command.


3 Answers

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.

like image 179
Chinmay Kanchi Avatar answered Oct 12 '22 19:10

Chinmay Kanchi


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

like image 31
JoshAdel Avatar answered Oct 12 '22 18:10

JoshAdel


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.

like image 35
plaes Avatar answered Oct 12 '22 19:10

plaes