I am trying to run a qblast from the Python prompt and after importing all the libraries I need, Python cannot find my file:
>>> record = SeqIO.read(open("sinchimeras_1.fasta"), format="fasta")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'sinchimeras_1.fasta'
I have tried to write down all the route for the file ("/Users/imac...") and to move the file to the Python and to the Biopython folders, and I get the same message.
Where do I have to save my file? What am I doing wrong?
You need to move that file to your working directory or use an absolute path.
This problem is independent of Biopython; the IOError is coming from open("sinchimeras_1.fasta").
Explanation
When you provide Python the relative path "sinchimeras_1.fasta", it looks in the current directory for such a file. So, instead of moving your Fasta file to a Python/Biopython folder, ensure it's in your working directory (os.getcwd() may be helpful).
Alternatively, you can supply the absolute path to the file in place of "sinchimeras_1.fasta" (e.g. open("/Users/imac.../sinchimeras_1.fasta")).
Related
txt = open("statistics.csv")
Keep getting this error, FileNotFoundError: [Errno 2] No such file or directory: 'statistics.csv', however the file is in the same folder as main.py
Projects:
US_statistics:
statistics.csv
main.py
tried using path
C:\Users\user_name\OneDrive\Documents\CODE\Programs\Python\Projects\US_statistics\statistics.csv
yet I still get the same error.
used os.getcwd and os.path.realpath(file) and paths match up to where the files are.
Try to run it directly over
python main.py
instead of in a environment or over the run button from Visual Studio Code
this should work?
If you use Visual Studio Code
You should note that you have opened the working environment exactly from inside the folder where the Python file is located
I am trying to run a beam job on dataflow using the python sdk.
My directory structure is :
beamjobs/
setup.py
main.py
beamjobs/
pipeline.py
When I run the job directly using python main.py, the job launches correctly. I use setup.py to package my code and I provide it to beam with the runtime option setup_file.
However if I run the same job using bazel (with a py_binary rule that includes setup.py as a data dependency), I end up getting an error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/dataflow_worker/batchworker.py", line 804, in run
work, execution_context, env=self.environment)
File "/usr/local/lib/python3.7/site-packages/dataflow_worker/workitem.py", line 131, in get_work_items
work_item_proto.sourceOperationTask.split)
File "/usr/local/lib/python3.7/site-packages/dataflow_worker/workercustomsources.py", line 144, in __init__
source_spec[names.SERIALIZED_SOURCE_KEY]['value'])
File "/usr/local/lib/python3.7/site-packages/apache_beam/internal/pickler.py", line 290, in loads
return dill.loads(s)
File "/usr/local/lib/python3.7/site-packages/dill/_dill.py", line 275, in loads
return load(file, ignore, **kwds)
File "/usr/local/lib/python3.7/site-packages/dill/_dill.py", line 270, in load
return Unpickler(file, ignore=ignore, **kwds).load()
File "/usr/local/lib/python3.7/site-packages/dill/_dill.py", line 472, in load
obj = StockUnpickler.load(self)
File "/usr/local/lib/python3.7/site-packages/dill/_dill.py", line 462, in find_class
return StockUnpickler.find_class(self, module, name)
ModuleNotFoundError: No module named 'beamjobs'
This is surprising to me because the logs show above:
Successfully installed beamjobs-0.0.1 pyyaml-5.4.1
So my package is installed successfully.
I don't understand this discrepancy between running with python or running with bazel.
In both cases, the logs seem to show that dataflow tries to use the image gcr.io/cloud-dataflow/v1beta3/python37:2.29.0
Any ideas?
Ok, so the problem was that I was sending the file setup.py as a dependency in bazel; and I could see in the logs that my package beamjobs was being installed correctly.
The issue is that the package was actually empty, because the only dependency I included in the py_binary rule was that setup.py file.
The fix was to also include all the other python files as part of the binary. I did that by creating py_library rules to add all those other files as dependencies.
Probably the wrapper-runner script generated by Bazel (you can find path to it by calling bazel build on a target) restrict set of modules available in your script. The proper approach is to fetch PyPI dependencies by Bazel, look at example
I am trying to run a python file called: "optimizer.py"
".py". Such file has several "import" lines, the first one being:
import optimizers.PSO as pso
on the same folder where ""optimizer.py" lives, there is a folder called "optimizers", where inside there are the many files mentioned in the imports, including the "PSO.py"
When I try to run the optimizer.py file, which the README.md mentions being the main file, all I get is this:
Traceback (most recent call last):
File "optimizer.py", line 8, in <module>
import optimizers.PSO as pso
ImportError: No module named optimizers.PSO
What can I be doing wrong? Perhaps is not my fault?
Fell free to ask for more info and thanks for the effort
Try copy the PSO.py to the folder of your main python file (folder of optimizer.py). then use import PSO as PSO.
Does anyone has a solution for this error?ยด
dan#LAPTOP-U61VD2F3:/mnt/c/Users/danyl/Desktop/New folder$ ruby "c:\Users\danyl\Desktop\New folder\Lesson.rb"
Traceback (most recent call last):
ruby: No such file or directory -- c:\\Users\\danyl\\Desktop\\New folder\\Lesson.rb (LoadError)
dan#LAPTOP-U61VD2F3:/mnt/c/Users/danyl/Desktop/New folder$
Solution in this case:
Go to your settings.json file in Vscode and add this line into the settings:
"code-runner.terminalRoot": "/mnt/",
or you can open settings and find Code-runner: Terminal Root and type this:
/mnt/
Note: For Windows system, replaces the Windows style drive letter in the command with a Unix style root when using a custom shell as the terminal, like Bash or Cgywin. Example: Setting this to '/mnt/' will replace 'C:\path' with '/mnt/c/path'
I am looking a read an mp3 file currently located in my public folder.
I have tried the following:
2.5.3 :016 > audio_file = File.new('/demo.mp3', 'rb')
And it resulted with the following error:
Traceback (most recent call last):
3: from (irb):16
2: from (irb):16:in `new'
1: from (irb):16:in `initialize'
Errno::ENOENT (No such file or directory # rb_sysopen - /demo.mp3)
I would assume this is pretty straight forward but for some reason it does not work. Does anybody knows how to do that ?
Alternatively, would it be possible to read a file that is located in a server via an http://xxxxxxx.xxxxx/xxxx/mp3 for example ? (This is where the file is located initially).
You've got the wrong path. /demo.mp3 will look for the file at the root of your file system.
If it's in public/, then you need to specify the path using the relative path public/demo.mp3 since the app is running from the project folder (supposedly) which contains the public/ folder.
You can also use path "#{Rails.root}" + "/public/demo.mp3"