Cannot import any modules to my python project - python

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.

Related

Trouble with imports on Visual Studio 2022

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.

Run a . exe file genarated using pyinstaller outside my venv is not working

I converted a xxxx.py to a yyyy.exe using pyinstaller, after a lot of modifications, and googling I managed to make the yyyy.exe work inside my venv, but when I switched outside venv(base), the yyyy.exe did not work, it seems that when yyyy.exe is executed,it still looking to import libraries from site packages in my local machine insted of looking inside dist folder where all needed libararies are installed. I do care about this issue since I m going to share only my file.exe with collegues not (file.exe and the venv) And it should work for them.
Any help is really appreciated.
I think your program has a dependency problem.
You have to install(build dependency tree) the .exe file before running.
You have to build an installer for it.
See:
Inno setup
for a good package creator.
here is a good tutorial:in youtube
Note, there are many good options for this work, feel free to check out them.

How to install a custom, local Python Package with Anaconda?

I have Anaconda2 running smoothly on Eclipse's PyDev environment.
I have received a custom package from a colleague in the form of a folder with a "library" sub-directory that contains many ".pyc" files (which I presume are the function files) and a "init.py" file. But no matter what I do, I cannot seem to install the folder as a package.
I have tried everything posted here in the Anaconda Prompt (which I'm assuming was the correct way of implementing the instructions)
http://conda.pydata.org/docs/using/pkgs.html#install-non-conda-packages
but nothing worked.
I am very new to really working with Anaconda, Python, Eclipse, and PyDev (I have only written simple scripts with the default IDLE IDE in the past).
All I really want to be able to do is to use the package of functions given to me - even if they are not properly "installed", although that would be ideal. If anyone out there can help me with this I would be very grateful!
Pyc are precompiled files, you dont need them.
You should simply import package folder with
import folder-name

Inconsistent Import Error in Python

I just have a quick question about an error I've been getting when I try to import:
from psychopy import gui
So if I try to import this code in one program I have no problems, however, if I try to import it in another I get:
"ImportError: cannot import name gui"
Does anyone know why this might be happening? Why does it work for one problem, but not the other? Also, I feel like it wasn't doing this before, and it just started suddenly. Any advice would be greatly appreciated.
UPDATE: I think Jon's answer is the correct one. If I was right, you should get an error "no module named psychopy".
Given that you tagged this question with the psychopy tag, my guess is that it works if you run it from the psychopy app and that it doesn't work if you run it from another editor or command line.
The reason is that psychopy is currently shipped as a bundle that comes with it's own python and a lot of modules/dependencies, including psychopy. The system is not made aware of these modules via the PYTHONPATH.
You can make them available system-wide by either (1) following the steps outlined here or (2) use the conda based installation described in this post in the psychopy-dev list. The latter feature is still work in progress but will probably eventually mature to be the default install option.
I think the other answers are wrong ;-)
I think if you had a different virtual environment or installation then the error in your code would indicate "No module named psychopy"
The fact that it finds something called psychopy but no sub-module called gui is a different problem. Often this occurs if you have a folder or file called psychopy next to you current working directory (eg. next to where you launch the script). Then Python thinks that's the psychopy module but can't find gui within it.
So, do you have a folder called psychopy? Rename it psychopyStuff.
I think you are using different virtual environments for both the projects, and so the package is installed in one virtualenv, and not in the other.
To verify this is the case, do a pip freeze in both the projects and compare the results.
If there is a single environment, the output will be same, otherwise the outputs will be different amongst the two.

Module importing in python 2.7

this is my first post and I've been working with python for about a month now.
Anyway I've been trying to import downloaded modules into python 2.7, such as django and mechanize, and I keep getting the same error telling me there is no such module. I downloaded both with pip and from I understand should be in the correct directories. A while ago I decided to simply copy and paste the django folder into the same folder I was saving my programs into, and that took care of the issue. That seems a bit messy though, having to save all of my modules into various folders. So I looked around stackoverflow (and elseware) and pasted that same folder into a PYTHONPATH directory and that didn't solve the problem either. I apologize for the long question but I've been at it for a while now and tried a few different fixes. Any feedback would be greatly appreciated, thank you very much.
On a side note, default modules work fine, such as: math and os. Side note, I'm running kubuntu 14.04.
Thanks again.
The standard Python solution to installing packages is to install pip (package manager) and virtualenv, then make a virtualenv for each project and install your packages in the virtualenv. The documentation for those projects is quite good and should be able to get you started.

Categories

Resources