Python Local development how to check syntax error - python

I am new to Python. I am working in a large project with multiple languages and one component is in python. That means I cannot run this python component in my Pycharm.
So I modified some python code. How do I know if I have any syntax errors?
In C++ I always compile it then I can see what errors I have so I can fix them.
Thanks!

Related

Strange path when compiling python in VsCode

everyone. I've been using python for a while with PyCharm, however I decided to go back on VsCode because I'm used to it.
I installed the python extension, specified the interpreter and compiled a basic file. Everything seems ok, except a strange path in the terminal which is annoying.
When I compile JavaScript it specifies the path rather simple:
C:\Program Files\nodejs\node.exe tests.js
However when I compile python it is a lot bigger:
PS D:\Projects\> ${env:DEBUGPY_LAUNCHER_PORT}='12345'; & 'C:\Users\user1\AppData\Local\Programs\Python
\Python38-32\python.exe' 'c:\Users\user1\.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles
\lib\python\debugpy\no_wheels\debugpy\launcher' 'd:\Projects\app.py'
My question is, is this normal and is there a way to remove it or should I get comfortable with.
Two things. One, that's not compiling your code, it's running your code under the the debugger. Python doesn't really have a compiler step in the traditional sense.
Two, there isn't anything you can do about it. It's how the debugger launches.

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

Visual Studio 2017 not recognising errors in code

I just installed the Python development workload for VS 2017 but the editor shows none of the red squiggly underlining for syntax errors that I'm used to seeing with C# on VS, nor any entries in the error list. If I try to run the code with errors, it warns me there are errors in the code but does not specify what they until exceptions are thrown from running.
I've tried reinstalling the workload and looked through every available option under the Tools/Options tab but can find nothing about syntax errors. Any fixes detailed for earlier versions of VS no longer seem to apply, what am I missing?
I had exactly the same problem using the simplest project from the VS Python tutorial.
The fix was to upgrade from VS 15.4.1 to 15.5.
Walt
I have had the same thing happen to me. Though this was actually with a C# application. I noticed Visual Studios stopped detecting the errors after adding a few NuGet references and doing some manual modifications of the project files. I noticed that this was only happening on this one project. All the other projects I worked on did not seem to have the same issue.
I was able to get it to start working again by creating a new project, moving my code over, and adding the references back one by one. For this situation, it looked as if a corrupt project file or bad reference was to blame even though the project would compile and run correctly.
Does this issue exist in other programming languages/projects?

Updating Python module in Matlab

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.

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.

Categories

Resources