ImportError at /mysite/ No module named bleach - python

I tried to google this tirelessly and couldn't get help at all.
I just pip install bleach and when I tried using in my views.py, import bleach it says ImportError at /mysite/
No module named bleach
I installed from this directory in command prompt:
(env) C:\Python27\Lib\site-packages\env\Scripts\myproject\mysite>pip install bleach
What am I doing wrong?

Installing as admin screws the whole point of using virtualenv
When using virtualenv you are setting a custom place for your libraries. You can use pip install my-package from anywhere after you activated the env and it will place the files in the same place.
While you are in your env try pip_freeze to see what is currently installed in your virtual env.
If you are interested in troubleshooting this issue, run the freeze and check if you are using env as you should.

Related

Virtual Environment Being Ignored or Overridden

I have been having an issue where pip and python seem to be ignoring the fact that they are in a virtualenv. I found the following:
pip command in virtualenv ignored in favour of system pip command
pip not pointing to virtual enviroment, in virtual enviroment
But neither seem to answer my issue.
The key issue seems to be when pip is trying to install modules it is detecting the module at the system level and then thinking it is already there, tries to uninstall it then fails because it isn't in the same environment.
For example, I need to update Wernzeug, so I try:
[venv] me#somemachine: pip install werkzeug
which results in:
Requirement already satisfied: werkzeug in /python/3.7.2/rh60_64/modules (0.15.2)
The weird bit starts if I run an uninstall:
[venv] me#somemachine: pip uninstall werkzeug
When I get:
Not uninstalling werkzeug at
/python/3.7.2/rh60_64/modules, outside environment
/venv Can't uninstall 'Werkzeug'. No files were found to uninstall.
Here's the kicker, due to the way the server is built I'm having to use the 'sw' command to get python (in this case 3.7.2). I'm wondering if this has something to do with the venv getting confused with where it is supposed to be looking. I do not have root access to the server, nor am I likely to get it, so I can't mess with the system installed modules.
Other useful info:
The base system is REHL 6.6
pip -V output:
pip 22.0.4 from /venv/lib/python3.7/site-packages/pip (python 3.7)
Any pointers or ideas that might help this are more than welcome.

cannot install 'Fury' in python

I want to use this code:
from dipy.viz import has_fury
from fury import window, actor
so at first I installed the DIPY and Fury. but when I run pip install Fury it didn't work and this error was showing:
ERROR: Cannot uninstall 'vtk'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
I tried to uninstalled vtk but I couldn't and same error showed to me.
This error means that this package's metadata doesn't include a list of files that belong to it. Most probably, you have installed this package via your OS' package manager, so you need to use that rather than pip to remove it.
You can either reinstall the package for python while ignoring the installed version with
pip install --ignore-installed vtk
pip install --ignore-installed fury
or if you don't wanna do that you can use a virtual environment and install the libraries in the virtual environment.
see: Virtual Environments in Python

ImportError: Missing optional dependency 'openpyxl' still doesn't work after instllation

ubuntu 18.04, python3.8 and using pycharm.
Interpreter path in pychamr is correctly set.
while trying to read specific sheet in excel, using openpyxl it keeps on giving me ImportError.
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
I've installed using pip3 install openpyxl and it say requirement is already satisfied.
However when I run it again in pycharm it still outputs same error.
Requirement already satisfied: openpyxl mycomp/.local/lib/python3.8/site-packages (3.0.7)
Requirement already satisfied: et-xmlfile in mycomp/.local/lib/python3.8/site-packages (from openpyxl) (1.0.1)
My guess is since I am using venv it is not getting installed correctly in venv because when I look at the path upon install it is not where venv is.
When I do pip3 freeze on venv and after deactivating venv it looks like it has same installation.
for me worked typing the following inside an interactive session:
import pip
pip.main(["install", "openpyxl"])
I ran into something similar because pandas is using this behind the scenes.
Clean your local python environment or create a fresh virtual environment to use from your IDE. Then if possible, try installing your modules in one pip command instead of on multiple lines.
# THIS, substitute pandas for whatever module is using openpyxl
pip install pandas openpyxl
# NOT THIS
pip install pandas
pip install openpyxl
# VERSIONS
pandas==1.4.3
openpyxl==3.0.10
What helped in my case: installing an additional optional library
pip install defusedxml
It works to me:
1:
conda install -c anaconda xlrd
2:
import pip
pip.main(["install", "openpyxl"])
Deleting venv and creating a new one fixed the issue.
previous venv had all dependencies as base which did not make sense. Maybe error on venv? I am curious to know if anyone knows.

Import requests results in error even after installing and uninstalling multiple times

I am working in a virtual environment and I have installed and uninstalled requests multiple times, each time without any warnings or errors.
The weird part about my issue is that the ModuleNotFoundError is only thrown in certain places. When running my script (which imports requests), when I import the script, and when I import requests in the IDLE shell, I am given the error. (This is all done in the virtual environment - don't worry, I check multiple times!) However, when I run python from the command line and perform all of the above actions, I don't receive any errors.
Installed Packages
$ pip list
Package Version
-------------- ---------
beautifulsoup4 4.9.3
certifi 2020.12.5
chardet 4.0.0
idna 2.10
pip 20.3.3
requests 2.25.1
selenium 3.141.0
setuptools 49.2.1
soupsieve 2.1
urllib3 1.26.2
Specs
Python 3.8.6
Windows 10 Home, 64-bit
git version 2.29.2.windows.3
It seems like you are using vscode. The reason is that you might setup the virtual environment in vscode but terminal is not recognizing the virtual environment. Thus whenever you install the module it will install globally not in a virtual environment. So hence when you directly run the code you get the error but since terminal is setup for using system Python path instead of virtual environment than path thus terminal run the file with no issue . If you had setup the virtual environment than make sure you had setup
correctly.
Before installing requests module activate virtual environment by
source venv/bin/activate
than install the requests module by
pip install requests

ModuleNotFoundError: No module named 'requests'

I have installed the pip3 as well as requests package in my pc.Even then on running the command import requests on my shell,i am getting the following error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
I have to manually copy all the packages to my working directory to tackle this exception.
Find were your python is installed and find Scripts directory. Open cmd, go to this folder and type pip install requests.
For me it was like below:
cd C:\Users\myLocalUserName\AppData\Local\Programs\Python\Python36\Scripts
pip install requests
In PyCharm you should:
Go back to base configuration in "File" - "Settings" - "Python Interpreteter" (it is the path that ends with "...\python.exe")
Click on the plus and install this module by typing name in search field.
Choose this configuration and run it by pressing Ctrl+Alt+F10
For listing instaled modules for Python 3:
sudo pip3 list
For installing the request module for Python 3:
sudo pip3 install requests
Make sure that requestes module should have version starts with 2
Not correct
pip3 list
Package Version
requestes 0.0.1
I installed this and installed using
python -m pip install requests
Later :
PS C:\python\Scripts> pip list
Package Version
certifi 2021.5.30
chardet 4.0.0
idna 2.10
pip 21.1.3
requests 2.25.1
urllib3 1.26.6
Activate Virtual Environment
.\env\Scripts\activate
Install the dependencies,
pip install request
Been tackling this issue for 2 hours now, this solution did it!
Find your Python installation location and, specifically, the Scripts directory. Open cmd, and run the following:
cd C:\Users\<myLocalUserName>\AppData\Local\Programs\Python\Python36\Scripts
pip install requests
For me, I used the package manager within my IDE (Pycharm in this case) to see if 'request' was installed. Once I did that, then the error went away.
I also tried pip install, but I suspect I have multiple python on the system and pip didn't install to the correct python. This is why others are suggesting to install from a specific python installation.
In Linux or Mac, you can run 'which python' for additional clues.

Categories

Resources