Strange path when compiling python in VsCode - python

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.

Related

No module named <packname> - PyCharm

I have searched for the problem on the site, but could not find the case or a similar one. This one I checked also as the best matching
tihs one.
I am using the system interpreter, Python (v3.7.0), and I can access all the packages in the python IDE no import error or something like that. In fact, when I use PyCharm and try to use import statement in the script, it shows 'No module named ', and when I run the script on PyCharm or from a different source it works with no error. In other words, I have a problem only in IDE, and since PyCharm IDE shows an error that there is no module when I am scripting, I cannot use the PyCharm IDE things associated with that module such as auto-complete. Yet, when I run the script from any shell or IDE they all successfully run the codes.
I don't figure out what is wrong, but I will provided some images below.
I have been using PyCharm for the projects, lately I've probably done sth wrong, but not sure so that PyCharms throws an error in IDE while scripting. The thing is while scripting when I use import statement PyCharm does not recognize the module which is already installed.
I don't figure out what is wrong, but I will provided some images below.
1st
2nd
3rd
Did you checked the Project Interpreter? If the interpreter you are using is different from IDLE, this might happens. Go to Preference -> Project Interpreter, and check the interpreter you are using it now. You can also check the packages that are currently being installed right away.

Creating an actual, executable program from Python code

I very recently wrote a program for a friend where it simplifies some important daily calculations for him/her. Now, the problem I am having is that I want to compile the code into an executable program so that he/she can comfortably run it on their machine, perhaps with a simple graphical interface or whatnot.
I have tried using cx_Freeze with Python 3.3.0 64 bit but to no avail (the program simply refuses to start on their machine; I even tried generating an executable via 32-bit Python, but also to no avail). What I then thought was that I could perhaps generate an executable program via PyGame? But the fact of the matter is that I have never used any Python-related program except the IDLE, so I am not sure what to do and look for.
Another option would perhaps be to convert the Python 3.3.0 code to Python 2.x, but the problem is that I am not familiar with Python 2.x and neither is there any automated converter available (as far as I know). I was wondering whether anyone of you could direct me to any good sources/links, since those I have been ferociously Googling are rather inconcrete.
You could just use py2exe. It is compatible with python 3. I have seen tutorials for it on youtube.
You could try embedding it in a C program, and compiling that for your executable. A decent tutorial is in the python docs at http://docs.python.org/2/extending/embedding.html
PyInstaller "is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX" and gives you one standalone executable file.
Even as a noob Python user I have succeeded to pack my app using PyInstaller (relatively) easily.

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.

Debug crashing C Library used in Python project

complete Python noob here (and rusty in C).
I am using a Mac with Lion OS. Trying to use NFCpy, which uses USBpy, which uses libUSB. libUSB is crashing due to a null pointer but I have no idea how to debug that since there are so many parts involved.
Right now I am using xcode to view the code highlighted but I run everything from bash. I can switch to Windows or Linux if this is going to be somehow easier with a different environment.
Any suggestions on how to debug this would be much appreciated ;-)
PS: It would be just fine if I could see the prints I put in C in the bash where I run the Python script
You should see your printf() you put in C in your terminal, something is already wrong here. Are you sure that you're using the latest compiled library? To be sure, instead of print, you can use use assert(0) (you need to include assert.h).
Anyway, you can debug your software using gdb:
gdb --args python yourfile.py
# type "run" to start the program
# if you put assert() in your code, gdb will stop at the assert, or you can put
# manual breakpoint by using "b filename:lineno" before "run"
Enable core dumps (ulimit -Sc unlimited) and crash the program to produce a core file. Examine the core file with gdb to learn more about the conditions leading up to the crash. Inspect the functions and local variables on the call stack for clues.
Or run the program under gdb to begin with and inspect the live process after it crashes and gdb intercepts the signal (SIGSEGV, SIGBUS, whatever).
Both of these approaches will be easier if you make sure all relevant native code (Python, libUSB, etc) have debugging symbols available.
Isolating the problem in a program which is as small as you can manage to make it, as Tio suggested, will also make this process easier.
PS: It would be just fine if I could see the prints I put in C in the bash where I run the Python script
You didn't mention anything about adding prints "in C" elsewhere in your question. Did you modify libUSB to add debugging prints? If so, did you rebuild it? What steps did you take to ensure that your new build would be used instead of the previously available libUSB? You may need to adjust your dylib-related environment variables to get the dynamic linker to prefer your version over the system version. If you did something else, explain what. :)

Efficient ways for Python debugging when called from within C++ code

I have a C++ application (on Windows XP) that invokes some Python code. I currently use Winpdb as my python debugger.
Using winpdb as the debugger has some disadvantages since firstly, I need to add a pdb statement, and there is little control afforded to me during the execution since I add dynamic breakpoints.
Does anyone know of tools that can be used that work in a similar fashion to Visual Studio 2010 (or Visual Studio in general)? Most important for me is to be able to set up and remove breakpoints while the application is executing, much like we can do using Visual Studio.
I have looked at ActiveState Komodo IDE6 and Eclipse Python PyDev, but I do not think either one actually fits the bill. This is because I have various python modules that are initialized
using the C++ function call "Py_InitModule" with a name that might be different from the name of the .py file. There modules are not recognized by Komodo and Eclipse Python PyDev.
Please let me know if you have any suggestions. Thank you for your help.
Well, for me it seems that it'd work in PyDev... The only thing is that you have to attach the tracing to the debugger -- use pydevd.settrace(suspend=False) on the thread you want to trace and after that it should 'synchronize' the current breakpoints and their additions/removals ( more references: http://pydev.org/manual_adv_remote_debugger.html ) -- note that you could use pydevd.settrace(suspend=True) to work as a breakpoint as in in pdb.
I didn't really understand why you said it wouldn't work. Can you post your specific example of what's not working to see how that would be solvable? (some things may be customized in pydevd_file_utils.py to help in translating breakpoint paths).

Categories

Resources