-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doing "from _ import _" in py4cl #50
Comments
Python like most non-lisp languages makes a distinction between expressions and non-expression-statements; so you'd rather need to use |
Thank you very much for your help @digikar99. I wanted to also ask you, which is related to this: How do I also change the directory where the python process for py4cl loads? The SigMFUtils I'm trying to load is in a specific folder, and I need to be in that directory in order for the python process to find SigMFUtils. I know how to do this if I am just using python in a shell (cd directory && python .), but when it comes to py4cl, I'm not quite sure how that works. |
There's also another way to change the process directory once the process has started: in the case of python, it is |
@digikar99 Thanks so much for your help. As you can tell, I am not very good with python. :D I'll go ahead and close this. |
I apologize for reopening this issue. I'm actually having trouble with reading the .py file using the above code we talked about. Here is an example I'm having trouble with:
The above gives an error, even though the output of OS:GETCWD is the correct directory:
However, if I run the same code using python 3.9.6 in my shell:
I don't get any error and SigMFUtil gets imported correctly. SigMFUtils is a .py file (named SigMFUtils.py) in the directory that I chdir to. Is this a bug, or am I missing something? Thank you very much for your time! |
Erm... Check for: (python-exec "import sys")
(python-eval "sys.path") ; EDIT: corrected, thanks brandflake11! Okay, I wasn't exactly clear about this, but the first item of this list, sys.path[0], is the directory containing the script that was used to invoke the Python interpreter; I had assumed it already contains the current-directory of the program, but turns out that isn't exactly the case. So, the current working directory would need to be added manually; hopefully that does it for you:
|
Okay, I looked at this and tried some of it. A couple of things:
This needed to be a string in order for lisp to print out the paths from python. It just returned a symbol :sys.path otherwise.
It seems that sys.append is not a command you can run, but after a quick search sys.path.append was the right answer. I sys.path.appended the directory that contains the SigMFUtils.py file I'm trying to import. After appending the path to the directory I am working in, I am getting this error now:
Everything looks normal as if I was running python from the shell. I just can't seem to import this. Let me know if you have any more ideas, and if not, that's fine too! Thanks again for your help! |
My bad at several places! Apologies, and corrected.
Okay... the value in sys.path while running as a script includes the absolute path to the directory-containing-script instead of the relative; does appending the absolute path instead of the relative path './' work? May be the value of sys.path could be set from the py4cl/2 end in the future. |
No problem @digikar99! I actually have tried to add the ./ and absolute path to the sys.path. Does the order of sys.path matter? Do I need to start sbcl in the same directory as the .py file I'm trying to load? I run sbcl from slime if that matters. |
I don't think I know if the order matters; so your best bet (as usual in programming) would be to try and see, and/or consult stackoverflow. For a simple sample file I created on my system to test this, it worked as expected; but for anything more complex, I don't know python enough or have a module to test this with. You could also try changing the path of the lisp program to the relevant directory using |
Thanks so much @digikar99 for all of your help. I'll keep experimenting and see if I can find a solution. I appreciate your help. |
Hello,
I am not a python expert at all, but I was using this lisp package to convert some python code into a lisp project I am working on. How would one go about using py4cl to do this kind of python code:
from SigMFUtils import SigMFUtil
I have attempted to do this with PYTHON-EVAL like this:
(py4cl:python-eval "from SigMFUtils import SigMFUtil")
but this doesn't work and results in a python syntax error. Is there a way to from _ import _ with IMPORT-MODULE?
Thank you very much for your time and any help you can offer.
The text was updated successfully, but these errors were encountered: