Trouble with imports on Visual Studio 2022 - python

What I get when I try to run it
Nothing I'm trying to import is being recognized by the IDE. I do have to admit, I am a fairly novice programmer, and the process of successfully importing external modules (, the ones that don't come with python,) is very confusing to me right now. But from everything I could scrap online, it seems like for VS 2022 I first have to go to [TOOLS] > [PYTHON] > [PYTHON ENVIRONMENTS]. Then from the environments popout I select my python version (, which is 3.10 (64-bit),) update my pip if not already up to date, search for my desired package and download. The terminal said the download completed but the IDE still can't find the import.
My installed packages in my python environment
This is a problem I've been putting off for months, and in the past I downloaded the packages through the Windows command prompt instead of the IDE. I'm not sure if it's any different, I'm not sure if one is more right. The result was the same regardless, it didn't work. And after several uninstalls and reinstalls, I even tried moving the entire package folder into my project folder to see if anything would change. The import was accepted but something in the packaged errored out. Moving files like that doesn't seem like the correct way anyway, I just want to make sure I bring up everything I tried to fix this.
I suspect that solution is something super simple that I'm just overlooking or don't know. I still kind of think the package needs to be with my .py file in some way but I'm unsure. If you can save me I'd appreciate it because I've been stumped for a while now.
I know my code is super simple, but I just wanted to show the error. I get the error before it prints.

Related

VS Code is unable to locate python

I have been looking at similar problems and everyone has a promising solution which usually revolves around changing the interpreter path. I have done my best but have run out of solutions that I can think of. I'm hoping someone else knows how and thank you for any comments.
No version of python ever appears, I have tried to enter the path in the box at the top but have had no luck
I want to switch from 3.10 to 3.9 and this is when not being able to select the version of python became a problem. The picture above is from the terminal within VS Code
This is the default path I have entered in VS Code
The photo above is from the Windows command prompt, locating the active version of python
I would like to be able to use Python 3.10 in some folders and 3.9 in others, however at the moment I really just need VS Code to see 3.9, I imagine once I know what has gone wrong at this stage it will be smooth sailing from here.
I have already uninstalled and reinstalled pretty much anything I can think could be related
I really hope I have just made a stupid mistake somewhere and it is really obvious, thank you again

anaconda: the solving environment keeps failing and freezing

I'm a beginner at all this code stuff so recently I have been trying to get this hole excel and python thing working using visual studio code and anaconda but without fail sup lexes me into the moon, I mean just doesn't work searching around to find a way to fix but nothing its been annoying and I have been at it for months now so whenever I try to get it to work it doesn't I'm using this guide https://code.visualstudio.com/docs/python/data-science-tutorial to help work it but nothing in the end if someone could tell me the problem or an alternative I would appreciate it here is an image to accompany it
basically I open the anaconda prompt and enter the command that was given to me by the guide but it just didn't work

Cannot import any modules to my python project

So few days ago I realized I couldn't import a module called "nbt" that I recently installed, I didn't really bother too much about it because I didn't really have a big need of it.
So I kept going on with my main project, and managed to launch it yesterday and started working for the next update of the project. I needed a few more modules, and started doing some research, found a few and installed them. Now when I try to import the module, it says "Unable to import 'module-name'. And I got confused, installed a few more modules, and same on those too.
I checked to make sure they were being installed in the correct directory, and they are! All the modules that do work are there, the same as the ones I recently installed.
I have done some research, but I don't seem to figure out the issue! I tried adding paths, 'PYTHON_HOME'. And connected that to my 'python path' in my C drive. Still, it does not work!
Also tried re-installing python, no luck. I tried to re-install the 'Python' extension on VSC, and as you might know, did not work.
obs:
I have tried to make new python files in different directories, and that didn't work either.

PyInstaller using old non-existant code that’s been changed

I have a script that generates logs based on an equation. Initially I had no equation so it printed out “0”. I run the script through my IDE, the equation works. I compiled with PyInstaller, run it, it’s all the same, except the log is back to printing “0”.
Any idea what the cause could be?
I just spent quite some time struggling with the same problem, but found a solution. I know it's a bit late, but I'm leaving this for people who may find this useful in the future.
I have just found out that I had two versions of the folder containing my script: one of them was the one I was actively working with, and the other one was an outdated version whose existence I didn't even remember. Turns out PyInstaller was importing the outdated version instead of the one I was working with.
I figured this out by looking at the .toc files inside the build folder. I searched the 'Analysis-00.toc' file for my script, and found out that it was importing the wrong one. I deleted the wrong outdated script, cleaned all the pyinstaller files and created a new build. After that, it worked as it should.

How to package/ distribute python applications

I've spent countless hours trying to understand this and unfortunately I haven't gotten to an answer yet. Or at least I don't think I have.
First up I should say that I am a Java Developer. I've only recently started working with Python and the build-process is a bit...odd for me.
In my mind I write an application, I compile it to run and I package it into a .jar for other people to use. Either as a library or for end-users to execute and have fun with it. (ignoring stuff like maven or gradle...)
I wrote a little CLT in python that consists of ~6 files and I wanted to distribute it. From what I could find I was supposed to write a setup.py and I found some guides on how to do that but ... to be honest I'm not even sure what that did. I could get my source code bundled into a tar.gz with some other meta data or it would create some weird files that I don't know what to do with.
Then I found PyInstaller and it worked great to package everything into a binary. However I've run into some problems trying to create a Debian package and it has made me re-assess and question the fact that there doesn't seem to be something in Python (without having to use an external tool) that lets me package/ bundle/ whatever my application into a single file to be run.
And that's something I can't get my head around. I mean...before there were tools like PyInstaller and P2Exe and what not, how did people distribute their applications? Am I expected to write a C application, somehow include the python code in there and compile that? Sorry if this seems like a stupid question but I'm really asking. I've googled around so much and spent so much time on it and haven't found a satisfactory answer so I hope someone here can help me with this! Thanks.
If you package your Python code for pip, you can include some executable scripts that start your program. I don't know how the situation was 5 years ago when this question got asked, but nowadays pip is pretty much integrated with Python, to the point that there's a standard library module to bootstrap pip in case it's missing:
https://docs.python.org/3/library/ensurepip.html
The situation is different if you want to package an application for some other package manager, like Anaconda or the package managers of various Linux distributions, or as a Windows installer. Obviously, you'll have to create a separate package for each package manager or installation technique you want to support.

Categories

Resources