While setting up py.saunter on my system, I am getting an IO error for saunter.ini file.
Directory structure is exactly as shown in the example - https://github.com/Element-34/Py.Saunter-Examples
Below is the error message -
IOError: [Errno 2] No such file or directory: '/src/conf/saunter.ini'
ERROR: Module: Tests could not be imported
(file:/Users/.../PythonWorkspace/PySaunter/src/scripts/Tests.py)
I know there are lot of import related questions. Most of them suggest to add init.py if not already there. I have added init.py in every folder.
The code snippet which reads saunter.ini is as below -
def configure(self, config = "saunter.ini"):
self.config = ConfigParser.SafeConfigParser()
self.config.readfp(open(os.path.join("conf", config)))
Any help would be appreciated...
There isn't really enough here to diagnose the problem. But, in the examples directory there is actually two different projects (ebay and sauce) -- you have to be in one of them, not the top.
Also, Py.Saunter won't create saunter.ini for you. You need to create it (most easily by renaming saunter.ini.default).
Oh, and don't try and run it from checkout from Github -- it really does need to be from an egg. If there are bits missing from http://element34.ca/products/saunter/pysaunter which prevent you from getting started, let me know and I'll modify the page.
(Now if only I remembered by SO credentials...)
I was running the project from eclipse as a unit-test which is why it was throwing import errors.
Py.Saunter is an opinionated framework and does not support eclipse or any other IDE at this point.
It works fine when executed from the command line as illustrated in the site - http://element34.ca/products/saunter/pysaunter
Should ensure to execute from the home directory.
Related
My folder structure is:
|-fastapi
|-app
|-calc.py
|-tests
|-mytest.py
In mytest.py I'm trying to import calc.py, like this:
from app import calc
In mytest.py, app and calc are both highlighted green, and when I hover over them, it says (module). It seems to be recognized, but when I run it, I get the error. I know this has been asked before but I haven't found the solution.
I create the exact same file hierarchy in my machine and then made a random function called hello() in the calc.py file, this is the code which successfully calls the function in app folder,
import sys
sys.path.append('../')
from app import calc
print(calc.hello())
maybe I misunderstood the question so here's a much detailed answer with respect to behaviour of the IDE when importing a module,
as we can see in the image below, we can import a wrong module in almost any python IDE and it won't give an error until or unless it is a smart IDE with preinstalled extensions to check as it does for other scripting languages or it won't give an error just yet, below it can be seen,
we can see that IDE doesn't show any error just yet doesn't even give a warning of any sort, but when you run the code you get this error, this is the same error which OP gets when they run their code,
this can be tried for from app import calc and it will give you same error as it gives for from imagination import dreams.
but when you add couple lines of code which are,
import sys
sys.path.append('../')
it starts to import in a similar way which OP was trying to do but only with the additional lines of code, why?
This is because they have their files in parallel to each other, which can be seen in the folders which they mention,
|-fastapi
|-app
|-calc.py
|-tests
|-mytest.py
perhaps this answers the concern which a comment mentions, I took the liberty to assume a few things but more or less this is what's happening, please rectify this answer.
You need __init__.py in each folder to mark it as a package. It can be an empty file. Check the docs for more information.
You should check and ensure you do not have an already existing file named 'calc.py'.
So bascically I have a filestructure lile
directory
/subdirecrory
>view.py
>view_model.py
>controller.py
>main.py
My controller looks something like:
import view
startChat()
#^ for testing, to see if the import works when directly calling file
def startChat(socket):
#datahandling
view.startGui()
My view is simply:
import tkinter
def startGui():
gui = tkinter.Tk()
gui.mainloop()
And lastly, the main is:
from subdirectory import controller
if __name__ == '__main__':
controller.startChat(s)
I removed all the meat to reduce myself to the GUI starting. When I run the controller everything works as it should, if I put the main into the subdirectory it also works.
Important note: This is a fix, but not what I want. I will soon again need different files, folders and directories and unless there is no way to do this would like to know a solution to this problem that doesn't involve putting everything in the same folder.
If I run the program as it is right now, it will execute the controller.py, if i put a print() above the imports (of which i have a few, like sys and time, which all work), it will only fail once it reaches the import view
The errormessage is a:
Exception has occurred: ModuleNotFoundError
No module named 'chat_view
My theory is that when calling from another directory the runtime has no info about the folder it is put into, and can't do what would happen if I started it from the directory. Which is what I tried to fix in the first and third solution of the other things I have tried so far:
Putting "from subdirectory import view" but that didn't work
Looking up this question on Google to no success
Importing the view in the main
Adding an init.py into the /subdirectory
As you might see I am more trying around and guessing and I think it's unlikely I find the solution to this anytime soon, so I thought to ask here. I wouldn't be surprised if this is a duplicate, but I wasn't able to find what I was looking for.
Instead of an absolute import, you can use a relative import in your controller
from . import view
the dot means it will search in the same folder.
A weird thing worked that I hope someone else can EXPLAIN, but here for future reference what I did was:
I put all the files into a directory names "src" like
directory/src #this is how it is displayed in VSC, idk why it is not displayed as extra directory but like this?
main.py
/subdirectory
__init__.py
#other files
I did this to clean up my code but then in the controller the import import view didn't work anymore, so when I changed it to from subdirectory import view (which earlier caused an error) it now works calling it from the main.py
This is bizarre to me as all I did was add a directory, but it works, so, yes. This is the accepted answer for now, until someone explains it better than me then I will switch it
An intern of mine is trying to use deeptools' bamCoverage function, and it throws a '/my/dir/data.bam' file does not exist error, despite the file being there. Yes, the file does exist, we can manipulate it using bash commands just fine so there's no real reason for it to throw that error.
According to this thread, it could be an issue with pysam or python. Both are fully up to date. Do you know how I could investigate issues with pysam or python IO further?
All of this is happening on a server that our team uses. Could it be an issue with python's paths for his user session?
For reference, here is the code I'm running in my bash terminal. It's pretty basic:
my.name#server:/mnt/data1/my.name/PROJET_X/DATA/BIGWIG$ bamCoverage -p 8 -b /mnt/data1/my.name/PROJET_X/DATA/BAM_sort/G0-G00.Inputs.sorted.bam -o /mnt/data1/my.name/PROJET_X/DATA/BIGWIG/G0-G00.Inputs.RPGC.bw --normalizeUsing RPGC --effectiveGenomeSize 2913022398 -bs 10
The file '/mnt/data1/my.name/PROJET_X/DATA/BAM_sort/G0-G00.Inputs.sorted.bam' does not exist
my.name#server:/mnt/data1/my.name/PROJET_X/DATA/BIGWIG$ ll /mnt/data1/my.name/PROJET_X/DATA/BAM_sort/G0-G00.Inputs.sorted.bam
-rwxr-xr-x 1 my.name bioinfo 4171366400 juin 22 10:14 /mnt/data1/my.name/PROJET_X/DATA/BAM_sort/G0-G00.Inputs.sorted.bam
I have used this line probably 100 times this past year, but now it won't find the file.
I've also tried installing deeptools in my home directory using conda, but that gives the same errors.
EDIT: Apparently, it was just a problem with that one file. bamCoverage will work on other data files. It would be nice if deeptools would tell you that instead of just "file not found"...
It would be helpful to see what code is being run here - please,
provide a minimal reproducible example, including the full output / error, if at all possible.
Right now, I can think of 4 possible solutions to common problems:
As mentioned in the comments, providing the full path might be one solution. You can get the full path by using the pwd bash command in the folder where the file is stored and then add the file name at the end of the string.
Another thing that sometimes helps with relative (local) paths is to start the path with a ".", so the path would be something like this: './my/dir/data.bam'.
Another problem I've encountered (mostly when running things on Windows environments) was that the backslashes had to be used instead: '\my\dir\data.bam'
For the sake of completeness here, I'll mention that especially with beginning programmers, the path is often erroneously provided without commas (to make it a string), but that does not seem to be the case here.
Hope this helps!
I'm sure I'm doing something wrong(i.e. stupid), but running
from stuff.modules import maths
Pylint just keeps giving
No name 'modules' in module 'stuff' pylint(no-name-in-module)
Unable to import 'stuff.modules' pylint(import-error)
My stuff-module is located at /home/abb, so I tried to add both PYTHONPATH="/home/abb" and PYTHONPATH="/home/abb/stuff" to an .env-file, but since it still gives the errors, I think the problem is that I'm also using the stuff-folder as my workspace.
I don't think it's a problem with the .env-file, since I'm also importing from my lib-module located in the same folder as stuff, and this doesn't raise any errors.
(Oh, and if it is important, I'm running this on an SSH-connection)
I had a similar issue. I did 'fix' it by faking another path by using ProjectRootFolder.stuff.modules, saving, and typing again stuff.modules.
I know that it was not a real fix, but from then it worked, also it is stands ever marked with a red under-line.
I explained my issue here.
I had to edit python.analysis.extraPaths.
I tried the .env route and could not get it to work. I actually spent a couple hours on it.
If you go file->preferences->settings or ctrl+, you can search for "extrapath".
Just add your /home/abb/stuff there and it should work.
I’m trying to run some robot framework tests in eclipse. I have Python, PyDev, Robot Framework (and all other things which I need) already installed, but it comes always the same error message "Parsing failed: Unsupported file format 'py'". Does anyone know where the problem may lie? Thank you in advance!
You will get this exact error if you tell robot to run a file as if it was a test case (e.g. robot something.py). The solution is pretty simple: don't pass a .py file as an argument to robot.
can you tell what did you try until now ? i cant comment that's why i ll write my Comments here. I think it have something to do with filenames. Maybe you gave a filename to robot, and robot can't find that file.
Maybe it also means :
the file does not exist. For example, maybe you forgot to save the file
you misspelled the filename
you spelled the filename correct, the file exists, but it is in a different directory than the current working directory.
here is some Question that maybe will help you if you have the same Problem:
Run suite of suites using argumentfile option