0
votes

I need to use netcdf but do not have install permission for python modules. I have downloaded netcdf-0.1.2.tar.gz from here: https://pypi.python.org/simple/netcdf/ and unzipped the tar ball. I have been following this stack overflow post in an attempt to use the module but have had no luck so far: (Python) Use a library locally instead of installing it
here is what I have tried:

Installing virtualenv:
I do not have permission to do this

python setup.py install -- user:
again, I don't have permission

running my script with netcdf as my current working directory:
I tried this as well, here are the issues I have run into:
first I went into netcdf-0.1.2 and made a new file called asdf.py which contains the following:

import netcdf
print("testing")

running python asdf.py gives the following error:

Traceback (most recent call last):
  File "asdf.py", line 1, in <module>
    import netcdf
  File "/.../Downloads/netcdf-0.1.2/netcdf/__init__.py", line 1, in <module>
    from netcdf import *
  File "/.../Downloads/netcdf-0.1.2/netcdf/netcdf.py", line 1, in <module>
    from netCDF4 import Dataset, numpy
ImportError: No module named netCDF4

I'm not sure how to fix this error, any help would be greatly appreciated

in case this is somehow relevant, the version of Linux I am using is 3.2.0-23-generic

also I have numpy installed already

3
You can install Anaconda/Miniconda into your home dir. This would give all the needed rights. - Mike Müller
@MikeMüller the central issue here is that I can't install anything, if I could I would just install netcdf - Mathew
You don't need admin rights only rights to write in your home dir. - Mike Müller
@fred, sorry, I missed that. Now you should search for a module called netCDF4. I suspect it's either yet another module that you need to download separately and unpack in such a way that it's visible to netcdf, or it's hidden somewhere inside the netcdf folder, so that it should be moved in order to be visible. - ForceBru
ok, I found that one and downloaded it too but i'm not sure how to put the 2 together to make it work - Mathew

3 Answers

1
votes

Easest would be to install Anaconda or Miniconda with your user rights. Anaconda already as netCDF4installed. In case of Miniconda install with:

conda install netcdf4
0
votes

If you have Python 3 installed, then you will have the venv package in the standard library, so you do not need "virtualenv" to be installed for you separately (as would be the case with Python 2). Instead use python3 -mvenv , in a similar way to how you would use virtualenv, for example:

python3 -mvenv /path/to/my_venv

or to include any non-standard packages already installed on the system:

python3 -mvenv --system-site-packages /path/to/my_venv

After that, you should be able to activate the environment and pip install packages, e.g.

source /path/to/my_venv/bin/activate   # for csh use activate.csh instead
pip install netCDF4

Remember to source the activate script at run time as well as installation time:

source /path/to/my_venv/bin/activate
python

and you should then find that in your python session you have the netCDF4 package available, e.g.

import netCDF4
my_dataset = netCDF4.Dataset('myfile.nc')

Of course, substitute the actual path in place of /path/to/my_venv above.

None of this requires any root privileges.

(And as someone else has suggested, another option for you is to use conda.)

0
votes

I'd also like to highlight that the package is imported using capitals

import netCDF4 as nc

This might not matter on a mac, but for Windows it is key.