Different versions in python and no modules named pip - python

I put a lot of effort into this and things are even worst I am desperate as hell. Only what I wanted was to download with a pip module called PySimpleGUI and after, that things started to get worse and worse. I program plugins for blender and I wanted to execute another python file as a subprocess that needs PySimpleGUI for its running. So after the first not very successful attempt at solving the pip problem here(Why am I getting ImportError: No module named pip ' right after installing pip?), I decided to delete all the python files and versions on PC and start all over again with installing python. But even though I delete all the python files I still got a message in CMD about my version and that says my version is 3.9.10 although I installed 3.9.7. I removed all paths in env. variables and also all python folders from
C:\Users\UserName\AppData\Local\Programs
C:\Users\UserName\AppData\Roaming
C:\Users\UserName\AppData\Local\Programs
and I think I deleted some folders also here out of desperation
C:\msys64\mingw64
Now if I try to write pip --version to CMD or python3 -m ensurepip (although I have installed python of version 3.9.7) this error occurs.
C:\WINDOWS\system32>"C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.exe" -m pip install tkinter -t"C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\lib\site-packages"
C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.exe: No module named pip
C:\WINDOWS\system32>python3 -m ensurepip
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\msys64\\mingw64\\bin\\python3.exe'
sys.base_prefix = 'D:\\a\\msys64\\mingw64'
sys.base_exec_prefix = 'D:\\a\\msys64\\mingw64'
sys.platlibdir = 'lib'
sys.executable = 'C:\\msys64\\mingw64\\bin\\python3.exe'
sys.prefix = 'D:\\a\\msys64\\mingw64'
sys.exec_prefix = 'D:\\a\\msys64\\mingw64'
sys.path = [
'D:\\a\\msys64\\mingw64\\lib\\python39.zip',
'D:\\a\\msys64\\mingw64\\lib\\python3.9',
'D:\\a\\msys64\\mingw64\\lib\\lib-dynload',
'',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000000b4 (most recent call first):
<no Python frame>
Only what is changing is current thread (Current thread 0x00004604, Current thread 0x00001dec,Current thread 0x00004e18)

I seem to have had a similar problem, it seems to be a problem of mixing up multiple different Python interpreters. Blender has an embedded Python interpreter, this can be seen in your error message
C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.exe: No module named pip, this is blender python not having pip, C:\WINDOWS\system32>python3 -m ensurepip is then ran but it's not the same python, here's the python version you installed.
Following this guide has worked for me, the main idea is to
cd C:\Program Files\Blender Foundation\Blender 3.0\3.0\python
As you already attempted you need to run the module ensure pip (but with python blender). So:
.\bin\python.exe - m ensurepip
You can now run
.\Scripts\pip3.exe install PySimpleGUI
or whatever module and it should be accessible from within blender.
for more information (although I'm not sure how still relevant it is) https://blender.stackexchange.com/questions/5287/using-3rd-party-python-modules

I have tried to install pip by installing it using blender python like this:
C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.exe -m ensurepip
and then upgrade I upgraded it
C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.exe -m pip install --upgrade pip

Related

Unable to move the Stable Diffusion pipeline to my M1 MacBook

I am following the steps stated here: How to use Stable Diffusion in Apple Silicon (M1/M2).
At my local MacBook M1 machine, I saved the below script in stable-diffusion.py file:
# make sure you're logged in with `huggingface-cli login`
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("mps")
# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()
prompt = "a photo of an astronaut riding a horse on mars"
# First-time "warmup" pass (see explanation above)
_ = pipe(prompt, num_inference_steps=1)
# Results match those from the CPU device after the warmup pass.
image = pipe(prompt).images[0]
Now when I am trying to execute: python stable-diffusion.py from Terminal, I am getting following error:
Traceback (most recent call last):
File "/Users/apple/Desktop/area_51/stable-diffusion.py", line 2, in <module>
from diffusers import StableDiffusionPipeline
ModuleNotFoundError: No module named 'diffusers'
In order to fix it even I tried: pip install diffusers, however I still got same error.
Am I missing anything over here?
If you have already installed diffusers but are still encountering the ModuleNotFoundError, it's possible that the module is installed in a different Python environment than the one you are running your script from. In that case, you may need to check your Python environment settings and ensure that the module is installed in the correct environment.
To check your Python environment settings, you can use the following steps:
First, determine which Python interpreter you are currently using by running the following command in your terminal:
which python3
This should output the path to the Python interpreter that is currently being used. (I assume you're using python3. If you are using python2 for some ungodly reason, you should switch to python3.)
Next, ensure that the diffusers package is installed in the environment associated with the Python interpreter you are using. You can do this by running the following command:
python3 -m site
This will output information about the Python installation, including the location of the site-packages directory where installed packages are stored.
Look for a line that says "sys.path" or "USER_SITE" to find the location of the site-packages directory. This is the directory where Python looks for installed packages.
Check if the diffusers package is installed in the site-packages directory. You can do this by looking for a directory called diffusers inside the site-packages directory.
For example, if the site-packages directory is located at /usr/local/lib/python3.9/site-packages, you can check for the diffusers package by running the following command:
ls /usr/local/lib/python3.9/site-packages | grep diffusers
If the diffusers package is installed, this command should output a directory called diffusers. If the package is not installed, the command will not output anything.
If the diffusers package is not installed in the correct environment, you can try installing it using the appropriate package manager for that environment. For example, if you are using a conda environment, you can try installing the package using conda (conda install -c conda-forge diffusers). If you are using a virtual environment created with venv, you can try activating the environment and installing the package using pip (pip3 install diffusers).

Package installed but doesn't import package

For some odd reason no matter which package I install when I go to import it doesn't know what package I'm talking about. I am very certain this is a Visual Studio Code error but if not I am also using Linux.
When I pip install the package pyttsx3 this is what I get in the Terminal:
Collecting pyttsx3
Downloading https://files.pythonhosted.org/packages/24/4e/580726c73272344d3e74b7aaffae55ff6b6450061fbecb8cc6e112531c02/pyttsx3-2.7.tar.gz
Building wheels for collected packages: pyttsx3
Running setup.py bdist_wheel for pyttsx3 ... done
Stored in directory: /home/secretlloyd/.cache/pip/wheels/a2/8a/fe/11112aca9c89142c3a404bc67ef3393a7ad530da26639a05d4
Successfully built pyttsx3
Installing collected packages: pyttsx3
Successfully installed pyttsx3-2.7
But when I run a example I get this error:
Traceback (most recent call last):
File "/home/secretlloyd/Visual Studio Code/Python/Finished/Text Colors/finished.py", line 1, in <module>
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'
You can use an virtual environment to install your libs. If you do that, each project will have its own scoped libs without affect your global libs.
How to use the virtual environment?
Enter the root folder of your project and then run the following commands on the bash:
$ py -m venv .env
$ source .env/Scripts/activate
After that you'll notice your bash will have a prefix like that (.env). Then you should install your libs:
(.env) $ pip install pyttsx3
In order to deactivate the virtual environment just run the following command:
(.env) $ deactivate
Setup VS Code Intellisense for Virtual Environment
If you're using VSCode you can set the correct python interpreter after setting up a virtual environment. Just follow the steps:
Open VSCode in your project
Press F1
Type: > python: select interpreter
Click on Enter path or find an existing interpreter
Click on Find
The navigate to .env > Scripts > python
3 possible cases:
The same thing happened to me when I did not notice I was using two Pythons at the same time one 2.7 and another one 3.6. Make sure to know where is your package being installed to the Python modules folder you really want to store it or in another one you did not know existed.
Your PATH might not be configured correctly, check out either if you are using Windows or Linux if your PATH variables are configured correctly. You can reset your configuration if you wish. (link= How to reload .bashrc settings without logging out and back in again?)
For some packages/libraries of Python the way of importing the library is different from the name you import it on your .py file. For example: You can install OpenCV library by [pip install OpenCV] but when importing it in a file you have to write [import cv2].
I hope you find this information helpful for your problem.

pipenv fails installing Django

I'm trying to create virtual environment in PowerShell with Python 3.9, using the pipenv command, but when I run pipenv install Django it says this:
Creating a virtualenv for this project...
Pipfile: C:\Users\Alnourrus\Desktop\cfeproj\Pipfile
Using C:/Program Files/Python39/python.exe (3.9.1) to create virtualenv...
[ =] Creating virtual environment...New python executable in C:\Users\Alnourrus\.virtualenvs\cfeproj-gGpEVtIi\Scripts\python.exe
ERROR: The executable C:\Users\Alnourrus\.virtualenvs\cfeproj-gGpEVtIi\Scripts\python.exe is not functioning
ERROR: It thinks sys.prefix is 'c:\\users\\alnourrus\\desktop\\cfeproj' (should be 'c:\\users\\alnourrus\\.virtualenvs\\cfeproj-ggpevtii')
ERROR: virtualenv is not compatible with this system or executable
Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versions of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem.
Running virtualenv with interpreter C:/Program Files/Python39/python.exe
Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: c:\program files\python39\lib\site-packages\virtualenv.py:1137: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "C:\Users\Alnourrus\.virtualenvs\cfeproj-gGpEVtIi\lib\site.py", line 67, in <module>
import os
File "C:\Users\Alnourrus\.virtualenvs\cfeproj-gGpEVtIi\lib\os.py", line 29, in <module>
from _collections_abc import _check_methods
ModuleNotFoundError: No module named '_collections_abc'
Failed to create virtual environment.
It appears pipenv is crashing because it attempts to create a folder that already exists. Try clearing the virtual env with
rm -rf `pipenv --venv`
If that fails because pipenv complains there isn't an associated virtualenv, you'll have to skip the shortcuts and look at the error message for what folder it doesn't like and delete it ( make sure you're deleting a subfolder of /virtualenvs and not something important like the pipenv bin )
rm -rf /Users/juyeong/.local/share/virtualenvs/django_workspace-CfQ2tbWB/
use python -m when creating a pipenv environment

blender pip whl module install issue

I have 2 pythons on my computer
One for eclipse and other applications and one for blender.
Computer python version here:
**C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32\Scripts**
Blender (2.79) version is here:
C:\Program Files\Blender Foundation\Blender\2.79\python\bin
I installed pip for Blender (I hope I did) and it is here:
C:\Program Files\Blender Foundation\Blender\2.79\python\lib\site-packages\pip
Then I do this in CMD:
C:\Program Files\Blender Foundation\Blender\2.79\python\lib\site-packages>pip install C:\Users\xxxx\Downloads\pydevd-1.3.2-cp35-cp35m-win32.whl
And get this:
Installing collected packages: pydevd
Found existing installation: pydevd 1.3.0
Uninstalling pydevd-1.3.0:
Successfully uninstalled pydevd-1.3.0
The script pydevd.exe is installed in 'c:\users\xxxx\appdata\local\programs\python\python35-32\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pydevd-1.3.2
But I get this error still in my script under Blender:
Traceback (most recent call last):
File "C:\Users\emamili\Documents\Posao\modeli\blendtest.blend\Run.py", line 9,
in
pydev.debug(SCRIPT, PYDEVD_PATH)
File "C:\Program Files\Blender Foundation\Blender\pydev_debug.py", line 25, in
debug
import pydevd
ImportError: No module named 'pydevd'
Error: Python script fail, look in the console for now...
Your pip seems to be installing it to:
c:\users\xxxx\appdata\local\programs\python\python35-32\ (which is in your Installing collected packages message).
pip is probably mapping to your pip inside python35-32\scripts\pip.exe and by being inside the blender\site-packages doesn't change that.
Search for your pip.exe inside C:\Program Files\Blender Foundation\Blender\2.79\python or execute the python from blender with python -m pip install pydevd.

how to create virtualenv with pypy?

running the following command
virtualenv -p /usr/local/bin/pypy pypy
exits with error like
Running virtualenv with interpreter /usr/local/bin/pypy
New pypy executable in pypy/bin/pypy
debug: WARNING: Library path not found, using compiled-in sys.path.
debug: WARNING: 'sys.prefix' will not be set.
debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
debug: WARNING: It is ok to create a symlink to it from somewhere else.
'import site' failed
AttributeError: 'module' object has no attribute 'prefix'
ERROR: The executable pypy/bin/pypy is not functioning
ERROR: It thinks sys.prefix is u'/Users/myname' (should be u'/Users/myname/pypy')
ERROR: virtualenv is not compatible with this system or executable
I'm running Mac OS X 10.8.1 (Mountain Lion) with CPython 2.7.3 and installed pypy 1.9 using Brew. virtualenv's version is 1.8.4
Using pre-built pypy binary for Mac OS X downloaded directly from pypy's website doesn't make any difference
This appears to be a regression in 1.8.4. While trying this out on my system everything worked fine with virtualenv 1.8.2, then I upgraded and now I get the same error as you.
I got the same error on Windows using virtualenv 1.8.2. Also similar problems with 1.9 and 1.10. What worked for me was to run it once to make the directory, copy missing files, then run again to complete it.
virtualenv -p c:\bin\pypy\pypy.exe pypy
copy c:\bin\pypy\lib_pypy \virtualenvs\pypy
copy c:\bin\pypy\lib-python \virtualenvs\pypy
virtualenv -p c:\bin\pypy\pypy.exe pypy
For windows this worked for me :
python -m virtualenv -p <Your PYPY installed path\pypy3.exe> <venv_name>
I got the solution
Just use pypy3.exe instead of pypy.exe there are two .exe in downloaded folder
virtualenv -p C:/pypy3.7-v7.3.5-win64/pypy3.7-v7.3.5-win64/pypy3w.exe <folder_name>
By default python comes with venv. But venv has no -p
Install virtualenv using pip
Then use direct virtualenv -p path/pypy3.exe <folder_name>
no need to use python -m
With pypy-4.0.1 and virtualenv 14.0.3, out of the box I get an error:
Q:\>c:\pypy\bin\virtualenv -p c:\pypy\pypy.exe my_pypy_virtualenv
Already using interpreter c:\pypy\pypy.exe
New pypy executable in Q:\my_pypy_virtualenv\bin\pypy.exe
debug: OperationError:
debug: operror-type: ImportError
debug: operror-value: No module named UserDict
ERROR: The executable Q:\my_pypy_virtualenv\bin\pypy.exe is not functioning
ERROR: It thinks sys.prefix is u'q:\\' (should be u'q:\\my_pypy_virtualenv')
ERROR: virtualenv is not compatible with this system or executable
Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versions of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem.
Searching the original pypy install for UserDict*, I found UserDict.py in lib-python\2.7 but in the virtualenv's lib-python\2.7 there was only userdict.py and none of the capitalized User files. Following the example of the other solutions, I removed the virtualenv's userdict.py and copied the original User* files, and reran the virtualenv command, and it ran without error.

Categories