Updating Python module in Matlab - python

I'm trying to run a Python script using Matlab's built-in py. It's pretty simple, but I'm running into some difficulty drying to debug an error in my code (which runs fine testing in my Python IDE but crashes when run through Matlab).
The issue is that Matlab seems to be caching the module the first time I call a function, and I can't figure out how to get it to recognize changes to the module without restarting Matlab. Is anyone aware of a way to avoid this issue?

This is the first limitation listed on the MATLAB documentation's Limitations to Python Support page:
Editing and reloading a Python® module in the same MATLAB session. To
use an updated module, restart MATLAB
Sorry. That said, that page might help you figure out what the issue is, as there are other limitations that might be coming into play. You might also find their page about troubleshooting Python errors useful.

Related

Visual Studio Python reccomendations from module are incomplete

I followed a tutorial for websockets in python and stumbled across the issue that pylance does not reccomend me the fuctions related to the class that I have imported from a module:
My Editor:
The Tutorial:
The Code Itself runs without any issue, so the Import seems to work, but I dont recieve the reccomendations in vs code. What is the reason for this or where could i debug something like this?
Thanks to wjandrea I found some thing I personally did not stumble acros before.
So a classic mistake happened to me when following a tutorial, I work on newer versions than the 1.5 year old video... Unfortunately the part talking about versions was in a nother part...
Long story short, in the mean time a bigger change for the websockets module appeared since the used functions are now imported lazily. Wich makes sense to reduce startup time incase you'll run a websocket server with the module.
Little info about lazy imports (for me it was the first time i heard about this intelligent feature)
Incase anybody else stumbles across this im currently on Python 3.10.7 and I am talking about websockets 10.3!
Back to the issue.
Pylance obviously can't make any reccomendations since the functions like websockets.connect(uri, ...) are just loaded if they are used in the runtime by the default websockets module so tools for code reccomendations inside the editor dont not know they are there..
I took a glance inside the module and through the indirect hint from wjandrea about the lazy imports inside __init__.py the listed dictionary made much more sense now! Based on this I could backtrack the Python scripts I need for my functions or rather Pylance needs to create those handy reccomendations for me inside vs code (or any other ide).
For now I just manually imported the desired script so I have a bit more guidance while writing and since startuptime in my current project is not crutial I let the manual imports exist or i´ll just change out the import variations based on the cirumstance if I am currently developing or if the code goes into production.

Utilizing python code within swift using 3rd party software

so I'm pretty new to both swift and stack, but I have a problem with implimenting Pythonkit. But basically to provide a short summary, the kit basically allows you to be able to utilize python inside of swift (using certain swift functions in order to save variables, do functions, however, can execute the code of a .py file).
In the process of doing this however this error pops up
Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.: file /Users/****/Library/Developer/Xcode/DerivedData/Y******L-
So I tried updating my Python software to 3.0 and above (I'm not quite sure, I think it was 3.7), however when I run python it shows it is at version 2.7. This kind of confused me a bit, however it was until the error did I notice something was wrong. Why does it show that error? What does it mean?
(I did find a similar post with a similar error in stack overflow, however I don't have enough reputation to comment as well as I don't think the answer was addressed to what I wanted so I'm just going to continue writing here)
The swift code itself has updated (xcode11) and following the steps a lot of the functions have changed within Xcode, what is it that I did wrong that caused the error? Following the link it seems I have to utilize pyto? Checking that link the functions of pyto are different than the ones pf PythonKit. In PythonKit you can utilize python within your swift code, while pyto seems to be a python integration for iOS?
Any advice? And please ask if anything needs clarification, or if there's a different solution please tell me. Thanks,Vince

Using Jenkins to run Python script but having issue importing modules on the script

I am really new to Jenkins and Python so when I have initially researched for this problem, there has been a limit to my understanding. I am looking to write a Python script and for it to be run on Jenkins as part of some automated testing I wish to do. My script interacts with an API and hence imports the 'requests' module on Python. It works fine using the Python interpreter on my local machine but I have had issues when I have tried using the Jenkins Python script builder and so I am looking for a way around this.
As I mentioned, I have looked around the internet for solutions but as my knowledge on this topic is limited I have found it difficult to understand certain ideas that have been mentioned on the web. One lead I have had is related to the use of virtual environments on Jenkins, but as its something I've never used, I have struggled implementing it. I have installed the ShiningPanda Plugin on Jenkins, but I am unsure how to use it.
Any help given is greatly appreciated :)
Thanks

Is it possible to implement automatic error highlighting for Python?

Are there any IDEs for Python that support automatic error highlighting (like the Eclipse IDE for Java?) I think it would be a useful feature for a Python IDE, since it would make it easier to find syntax errors. Even if such an editor did not exist, it still might be possible to implement this by automatically running the Python script every few seconds, and then parsing the console output for error messages.
eclipse+pydev
pycharm
many others ....
If you use VIM or don't have a problem with it, try this extension. https://github.com/klen/python-mode
This is for Emacs as well: https://github.com/gabrielelanaro/emacs-for-python
Also pycharm and eclipse with pydev work fine.
If I don't use vim I really enjoy spyder. It is easy to use and has some really nice features, like integrated debugging and profiling, graphical variable explorer and object inspector. The latter shows, e.g., the integrated documentation for every function of class you use.
I built an extension to Eclipse and PyDev that does what you describe, it runs the Python code as you're typing, and displays all the variable values and any exceptions that occur. It's called Live Coding in Python, and the web site has a tutorial and a demo video.
PyDev can highlight some problems in your code by analysing it, and Live Coding in Python can show you problems that happen when you run it.

OpenCV 2.3.1 Python with Eclipse shows synatx errors but still runs

I followed this guide to setup OpenCV 2.3.1 in Python 2.7 with Eclipse.
I also copied the libraries into my python folder:
http://i.snag.gy/J9RrC.jpg
Here is my Hello World program which runs correctly (creates a named window and displays the image) but Eclipse still shows syntax errors
every error says "Undefined variable from import"
Here are my python settings for this project:
http://i.snag.gy/KBXiB.jpg
http://i.snag.gy/KfTpF.jpg
Have I setup my PythonPath incorrectly? How can i get Eclipse to work properly?
Thanks
I had the same problem, everything ran correctly even though there were undefined import errors all over the place. I eventually solved it by adding 'cv' to the list of Forced Builtins: Window > Preferences > Pydev > Interpreter - Python > Forced Builtins > New.
This is how I came across the solution:
How to use code completion into Eclipse with OpenCV
I hope that this may help you too.
EDIT: FYI, according to the top answer here, if you're just getting started (like me!) it's almost certainly better to use the cv2 interface instead of the older one provided in cv2.cv. The author of that answer, Abid Rahman, has some tutorials that look pretty good. (end EDIT)
I used Debian's tools to install the python-opencv package. There was no .../dist-packages/opencv directory to be found, and the cv.py file contained only:
from cv2.cv import *
I'm fairly inexperienced with Python and completely so with Python access to external libraries, so this looked like some sort of workaround related to that. Not so, apparently. I followed Casper's link above, and found the solution that he used (which worked for me,) but I wasn't happy using "forced builtins" when I wasn't entirely sure of the consequences.
However, the second, lower-rated answer there is my preferred solution. Instead of
import cv
I'm using
import cv2.cv as cv
From what I can tell, this just removes the cv.py middleman from the import chain, if that makes sense. A save/close/reload of my script had Eclipse recognizing cv.LoadImageM as defined and autocompleting other things from OpenCV.
I'm reproducing that answer here because it seems cleaner to me and I found this question first when I searched for the answer to the same problem.
It would be helpful to show the error you're getting and your code. However, I suspect that the problem is that the syntax errors which PyDev shows are based on its own parsing of the code, which is much more simplistic that the actual python interpreter. If your code runs, then the apparently undefined variables must be defined, but the PyDev parser just can't see them and reports them as "undefined".
The cause of this is that OpenCV doesn't explicitly define its variables in a way which can be read by PyDev. Unfortunately I don't have an easy solution. I usually deal with the problem by using from ... import ... so that the error only appears once. If you want you could write a wrapper module which explicitly imports the variables into its local namespace, then import that module instead.

Categories

Resources