I am getting the following error when I run my python script:
/Documents/stage/crocus/python$ python bonaiguaforcing.py
sh: 1: ncks: not found
sh: 1: ncatted: not found
Traceback (most recent call last):
File "bonaiguaforcing.py", line 142, in <module>
creatforc('/home/chomette/Documents/stage/crocus/bonaigua2.txt','/home/chomette/Documents/stage/crocus/FORCING_bonaigua.nc')
File "bonaiguaforcing.py", line 46, in creatforc
meteo=netCDF4.Dataset(net_out,'a')
File "netCDF4/_netCDF4.pyx", line 1746, in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:10983)
RuntimeError: No such file or directory
In my python script I create a netCDF file to copy data and then I create a new netCDF file with a new variable, it seems that python didn't find the first netCDF file created.... but I'm not sure.
Thanks for your help =)
Without seeing the code producing the error, this looks like an environment definition problem. Your shell can't find where NCO is installed (if you don't have NCO then this is a dependency problem and you need to install it for your script to work).
Have you tried in bash :
which ncks
which ncatted
If these are not in your path, you are going to need to add aliases pointing to them in your bash rc, execute under your home directory the following (with vi or another editor) :
vi .bashrc
then add to the file:
alias ncks='/usr/bin/ncks'
alias ncatted='/usr/bin/ncatted'
You will need to change /usr/ to the location of your NCO installation. Also, don't forget to source . .bashrc before testing your program again. You can also just type your aliases into the shell, but you will need to do this each time you open a new terminal.
Updated answer (based on your comment below):
now it appears that your script is not finding part of the netCDF4 module (the part of it written in c, hence the .pyx extension). You'll need to make sure that your environment is correctly defined and that the netCDF module has been correctly compiled. Before going any farther, type the following commands in a terminal:
python
from netCDF4 import Dataset
to make sure that the module exists. If that works, then you can follow the instructions on https://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4-module.html to create a dataset in order to make sure that the module was correctly compiled.
For information, are your porting the crocus model to a new machine ? If so, that might explain why you are missing so many dependencies (modules, libraries and operators that your code needs in order to function). If not, there may be another error in your script which is making this look like a dependency problem. Please post part of your script for generating the crocus forcings if you do not think this is a problem with your environment/dependencies (ie if someone has already run the same script on your machine and it worked). Thanks!
You're seeing a RuntimeError because the filename specified in netout does not exist--the 'a' mode (append) requires that the file exist.
Related
When I try to run my python projects, in some cases I get this error:
File "/usr/local/bin/AAA/camera_service/camera_service_main.py", line 6, in <module>
from views.hires_camera_handler_view import hires_camera_handler_blueprint
File "/usr/local/bin/AAA/camera_service/views/hires_camera_handler_view.py", line 7, in <module>
from hires_camera_handler.hires_camera_handler import HiResCameraHandler
File "/usr/local/bin/AAA/camera_service/hires_camera_handler/hires_camera_handler.py", line 3, in <module>
from ids_peak import ids_peak
File "/home/izx/anaconda3/envs/py38/lib/python3.8/site-packages/ids_peak/ids_peak.py", line 18, in <module>
from . import _ids_peak_python_interface
ImportError: libpython3.8.so.1.0: cannot open shared object file: No such file or directory
The object file exists in ~/anaconda3/envs/py38/lib
I can make the code run in my terminal by adding
export LD_LIBRARY_PATH=~/anaconda3/envs/py38/lib
However, there seems to be a deeper problem here, because more of my projects behave differently then on other ubuntu installs. I could of course reinstall ubuntu. But I would like to understand what I did wrong here.
Also, the solution above doesn't solve the issue. I can still not run my tests in PyCharm and that would be really beneficial. Probably I can somehow set this value in my pycharm run, however, setting the path variable didn't work and I wouldn't know how to do it.
I have tried various solutions. installing libpython3.8 (its already installed), installing libpython3.8-dev (its not available on ubuntu 22.04 jammy). I've also added the value to bashrc but as expected that doesn't solve it for PyCharm.
Can anyone explain to me exactly what the problem is here? Why is my conda environment not able to find its own lib folder? Why does adding the path to LD_LIBRARY_PATH work? It doesnt make sense to me that my conda environment needs the shared files when it got its own. What is the default location for conda to look for the shared files? How can this happen all of sudden when I have installed anaconda many times on many systems? I know these are a lot of questions, but I hope they can give me the answers I need to understand this problem instead of follow other SO-posts blindly.
Thank you
If your system is Ubuntu, you can find this file as I do and copy it to /lib/ or /lib64/
find / -name libpython3.8.so.1.0
sudo cp /home/zhou/anaconda3/envs/paddlep/lib/libpython3.8.so.1.0 /usr/lib/
or
sudo cp /home/zhou/anaconda3/envs/paddlep/lib/libpython3.8.so.1.0 /usr/lib64/
It is always worth reading the docs from anaconda:
https://docs.conda.io/projects/conda-build/en/latest/resources/use-shared-libraries.html#shared-libraries-in-macos-and-linux
You have to tell python where to find the additional modules by setting the PYTHONPATH in ~/.bashrc; Make sure to reload / restart the terminal or your IDE after updating ~/.bashrc
e.g.
export PYTHONPATH="${PYTHONPATH}:/Users/<myuser>/project_root_folder_path"
see Permanently add a directory to PYTHONPATH?
Hi,
I have a library called BioPython for Bioinformatics with several files.
I am unable to retrieve the file and it gives me the above errors.
My Python 3.8.2 IDE shell is in documents and my BioInformatics Library file is in documents as well. I think there is something wrong with the pathway of my package for python3.8 but I am not sure. Can someone guide me towards the right direction?
Keeping python shell and the file you want to access in the same directory does not matter. The only thing that matters is that your working working directory must have the file in order to import it without specifying the complete path.
Well, the error clearly shows that the name of the file has been either changed or it might have been moved to some other directory. It is better to specify the full path.
To learn python, I'm attempting the infamous baby names exercise.
I'm having trouble getting going. How do I import the file babynames.py from the folder C:\Users\user1\Desktop\google-python-exercises\babynames?
The directory is set to cd C:\Users\user1\Desktop\google-python-exercises\babynames, but the commmand import babynames is invalid.
I searched around for an answer, but most of the Google results I've found solve much more complex variations of this simple example.
Thanks for your time!
You shouldn't be importing the file - the instructions want you to edit the babynames.py directly. What you'll need to do is (assuming you're using spyder due to the tag on your question):
find and open babynames.py from Spyder
read through the file, follow the instructions, and edit where it is marked with your code here
run the file to test it. If you need to enter args (eg. for the default babynames code you need to give the output file with --summaryfile <file>.html, write them in the Command line options box in the run configuration dialog in Spyder.
If you're using the command prompt instead, you will need to edit the file using any text editor, and to run it, enter a command like: python babynames.py --summaryfile some-file.txt where the working directory is C:\Users\user1\Desktop\google-python-exercises\babynames and python is on your path. (you may need to give a different command to run python itself from cmd - it will depend on your setup).
Brand new to Python, coming from Ruby.
I have a script that works perfectly if I run it form ipython or ipython qtconsole. I then tried to turn it into an executable script -- threw #!/usr/bin/env python at the top.
Running the script throws an error:
$ ./script/myscript.py
Traceback (most recent call last):
File "./script/myscript.py", line 6, in <module>
import yaml
ImportError: No module named yaml
Obviously there's something wrong with how python is loading modules (as it works perfectly fine from the REPL) but I have no idea how to fix it.
Thanks!
What is likely happening is you have more than one version of Python installed on your system, and the yaml module is only installed in one of them. When you run ipython it's using one version, but your script's shebang line is finding another version. Run
head `which ipython`
and see if it matches up to the result of which python (I'm betting it won't). Once you know the path to the python binary being used by ipython, you can specifically define it in your script's shebang line.
As a long-term fix, edit your $PATH variable and put the directory containing your desired version of Python ahead of the directory shown by which python, so that you can continue to use #!/usr/bin/env python as a shebang.
ipython must be pointing at a different version of python than what is in PYTHONPATH.
You can find out by looking at cat /usr/local/bin/ipython.
Look at
ipython reads wrong python version
I am looking to run a file I created in python from a matlab script. I have checked that my python file works if I run it from the python interface. However I have not been able to get my python to run from matlab. The following is the code situation I am in.
In matlab., I have the following code:(My file name is pgcode.py)
! python pgcode.py
and interchangeably I have use this code as well:
system('python pgcode.py')
The error that results in matlab is:
"python: can't open file 'pgcode.py': [Errno 2] No such file or directory"
I have set my PATH directory and I really think this is an issue with setting the path so that I can find the file I have created but I haven't been able to figure out how to do this. I am using windows and Python 2.7.5. Any help is much appreciated. Thanks in advance!
There might be another way to do this, but here are two options.
First replace system('python pgcode.py') with system('pgcode.py'). Make sure that pgcode.py has execute permissions and in on your PATH. If you're using a unix/linux/mac type system, make sure pgcode.py has #!/usr/bin/env python as the first line, that's called a shebang.
Option two, is to use the full path when you call system(pathon /full/path/to/pgcode.py).
Hope that helps.
Your $PATH should control where python comes from, but I don't believe it will control where your pgcode.py comes from - at least, not in the way you're using it now.
You might want to either use a #!/usr/bin/env python and make your script executable, or be very mindful of what directory you're in when you try to python pgcode.py (you can prepend "pwd;" to your python command to see), or specify a full path to pgcode.py.
HTH