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
Related
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).
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
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.
I did this:
sudo pip install azure azure-storage azure-servicebus azure-mgmt azure-servicemanagement-legacy
from azure import *
Traceback (most recent call last): File "", line 1, in
ImportError: No module named azure
from azure.storage import BlobService
Traceback (most recent call last): File "", line 1, in
ImportError: No module named azure.storage
Python package installed thru cmd sudo pip install exists at the paths /usr/lib/python2.7, /usr/local/python2.7, etc and their sub-folder dist-packages.
You can code import sys and print sys.path in the Python Interpreter to show the completed path list for current python environment.
Iif you installed successfully some packages like azure & azure-storage, you can find these files relate to the package in the python library paths.
However, you got the error in Import Error: No module named <package-name> when you run the code import <package-name> or from <package-name> import <class or object name>. There are two scenes that would be cause the issue normally.
Package not installed successfully.
The library path included package that not exists in Python system environment path sys.path in python or PYTHONHOME in environment variables.
So I think you can try to solve the issue thru three ways below.
Dynamically add the package path into sys.path thru the method sys.path.append('<package path>') in python code.
Check the environment variable PYTHONHOME whether or not set up. If set up PYTHONHOME, python will add package path based on PYTHONHOME into sys.path.
If your python environment encounter some unknown fault that is unrecoverable, you can try to reinstall Python thru commands sudo apt-get remove python python-pip, sudo apt-get update, sudo apt-get install python python-pip on Ubuntu. It's a simple way.
BlobService belongs to azure.storage.blob rather than the azure.storage
it should rather be
from azure.storage.blob import BlobService
Link - https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/
If it still doesn't work for you, you might would like to use virtualEnv and do the pip install again while in virtualenv
http://docs.python-guide.org/en/latest/dev/virtualenvs/
I had very similar issue. There was a lot of confusion between python2 and python3 package versions as there was no virtual env used and I also had to ungrade pip to 18.
But anyway, this is is how I resolved the part in question.
Locate where the package was installed:
pip show azure
The output will show the location of the package in the Location section:
Name: azure
Version: 4.0.0
Summary: Microsoft Azure Client Libraries for Python
Home-page: https://github.com/Azure/azure-sdk-for-python
Author: Microsoft Corporation
Author-email: azpysdkhelp#microsoft.com
License: MIT License
Location: /usr/local/lib/python3.6/dist-packages
Requires: azure-servicefabric, azure-cosmosdb-table, azure-datalake-store, azure-loganalytics, azure-eventgrid, azure-servicemanagement-legacy, azure-servicebus, azure-graphrbac, azure-storage-blob, azure-mgmt, azure-storage-file, azure-batch, azure-applicationinsights, azure-keyvault, azure-storage-queue
Required-by:
If you do:
python -c "import sys;print(sys.path)"
You will see a list of pip package locations:
['/app', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
At the begining of my python file I added:
sys.path.insert( 0, '/usr/local/lib/python3.6/dist-packages' )
This will make sure this package location will be checked in the first place.
UPDATE
Thinking about it in the morning, things opened from a new perspective for me. I saw, that I had #!/usr/bin/python at the beginning of my python file, which says to use the wrong interpreter and look for pip packages in the wrong place.
azure metapackage is deprecated
and azure-storage is not being maintained anymore
Please use azure-storage-blob >= 12.0
pip install azure-storage-blob
from azure.storage.blob import BlobServiceClient
PS: I write SDKs for azure
Ubuntu Server in VirtualBox. I am trying to install VirtualEnv to start learning Flask and bottle.
Some details of my setup.
vks#UbSrVb:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="12.04.2 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.2 LTS)"
VERSION_ID="12.04"
vks#UbSrVb:~$ python --version
Python 2.7.3
vks#UbSrVb:~$ echo $VIRTUALENVWRAPPER_PYTHON
/usr/bin/python
vks#UbSrVb:~$ echo $VIRTUALENV_PYTHON
vks#UbSrVb:~$
When I boot my Virtual Machine, I get the following error on my console
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
When i try to initialize a virtualenv I get the following errors
vks#UbSrVb:~/dropbox/venv$ virtualenv try1
New python executable in try1/bin/python3.2
Also creating executable in try1/bin/python
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.9.1', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python3.2/dist-packages/virtualenv.py", line 979, in main
no_pip=options.no_pip)
File "/usr/local/lib/python3.2/dist-packages/virtualenv.py", line 1081, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/local/lib/python3.2/dist-packages/virtualenv.py", line 1499, in install_python
os.symlink(py_executable_base, full_pth)
OSError: [Errno 30] Read-only file system
vks#UbSrVb:~/dropbox/venv$ ls
try1
vks#UbSrVb:~/dropbox/venv$ ls try1/
bin include lib
vks#UbSrVb:~/dropbox/venv$
My .bashrc entries
export WORKON_HOME='~/dropbox/venv/'
source '/usr/local/bin/virtualenvwrapper.sh'
Q1 - As per the error at bootup, How do I ensure virtualenv is installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly ?
Q2 - Even with sudo I get the same "Read-only file system" Error ?
I have tried installing virtualenv using pip and then apt-get, just to hit and try.
Try setting your WORKON_HOME global to another path (~/.virtualenvs) for example a see if that works, maybe the problem is with that shared directory, are you using windows? If you are, try installing ntfs-3g, see https://askubuntu.com/questions/70281/why-does-my-ntfs-partition-mount-as-read-only
Also in my profile configuration file I like to detect first if virtualenvwrapper is installed:
if which virtualenvwrapper.sh &> /dev/null; then
WORKON_HOME=$HOME/.virtualenvs
# path to virtualenvwrapper, in my case
source /usr/local/share/python/virtualenvwrapper.sh
fi
I had the problem where my pip was for a different version of python than the one I wanted to use.
$ python -V
Python 2.7.5+
$ pip -V
pip 1.5.4 from /usr/local/lib/python3.3/dist-packages (python 3.3)
So when I used pip to install virtualenv and virtualenvwrapper, the new python packages were put in python3.3's dist-packages, so of course my python2.7 couldn't find them!
To fix this, I had to use the appropriate version of pip, in my case it was pip2.
$ pip2 -V
pip 1.5.4 from /usr/local/lib/python2.7/dist-packages (python 2.7)
So make sure you are using the appropriate version of pip.