No module named 'encodings' - python

My operating system is Ubuntu 17.10.
I have am trying to run (and develop) a python project, but when I do I get:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f8c459bf740 (most recent call first):
I have tried advice from ImportError: No module named 'encodings', namely:
I have removed old virtual environment,
create a new one, named venv
run source venv/bin/activate
pip install -r requirements.txt
Also, in pycharm, I have gone File > Settings > Project > Project Interrupter - and set this to use the same virtual environment.
I have also tried sudo dpkg-reconfigure python3
But I still get the same error.

I've found this message to be caused, on setting up uwsgi, by an invalid pointer to the virtual environment in the ".ini" file.

I was facing a similar issue "ModuleNotFoundError: No module named 'encodings" after updating to macOS Catalina.
I was having multiple versions of Python installed in my system.
Removing all the python versions(2.7 and 3.7.4) from macOS system and reinstalling the latest python 3.8 worked for me.
To remove a python from macOS, I've followed the instructions from here How to uninstall Python 2.7 on a Mac OS X 10.6.4?

Related

bson module not found when running script in VSCode, works fine within the same conda environment in terminal

I have created a new conda environment and installed pymongo from conda-forge. pymongo should install bson module as part of its installation and it does, as running my script from terminal works just fine. I checked the env path with sys.executable and set the same environment in VSCode. Then switched to VSCode terminal and called the script from there (just using python script.py), with the same environment activated. However, I got an error:
Traceback (most recent call last):
File "src/script.py", line 2, in <module>
import bson
ImportError: No module named bson
Any ideas what may be the source of the error? I feel like there might be some issue specific to bson module, as other packages seems to work just fine.
The reason is that the location where this module is installed is not in the python environment currently used by VS Code or the module file is damaged.
Please enter "python --version" or "pip --version" in the VS Code terminal to check the python environment used by the terminal, and the module will be installed here:
In order to avoid the impact caused by the damage of the module file, we can find the location where the module was installed, delete the module folder, and then reinstall it: (pip show module)
run:

ModuleNotFoundError: No module named 'tensorflow' Vs code

I am running on windows 10. I am having problems with importing TensorFlow. I am in Vs code. I installed tensorflow using pip3. And here is the error:
Traceback (most recent call last):
File "c:/Users/USER/PycharmProjects/tt/main.py", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I created my project in pycharm.
I am using python 3.7.5 and TensorFlow 2.0.0. This is how I installed TF:
pip3 install tensorflow==2.0.0
please help I was having this problem for a week.
Thanks , In Advance
For your work/project, please try to create a new virtual environment and then install all your required packages.
Like this:
$ python3 -m venv env
Activate it:
$ source env/bin/activate
and then install the tensorflow package inside your virtual environment:
pip3 install tensorflow
I think you need to create environment separate
and then install tensorflow..
for more information regarding envirnoment Link
Do you have several different python environments on your pc? Which python interpreter are you using when you install tensorflow?
The Status Bar will show you the current interpreter in the lower left corner. Check whether it is the same with the one you use when you install tensorflow.
enter image description here
I was getting your exact error, but this worked for me:
File->settings
Workspace tab
Search for "interpreter"
Put the complete path to the python.exe you want to execute under "default interpreter path"
It seems VSCode either found (or included) an older version of python that couldn't find the things I installed with pip.
I am a bit of a python newb and I'm guessing the venv approach is superior, but I couldn't get that cooperating with VSCode on windows.

ModuleNotFoundError: No module named 'requests' but it's installed?

I used the command pip install requests in CMD and successfully installed the requests module, but when I try and import it to my file in PyCharm it throws
"ModuleNotFoundError: No module named 'requests'
I saw a couple other posts about this issue but did not find a working solution.
As a side note I have successfully run this code in my Python IDLE so I presume this is not a code issue, and just an issue with my PyCharm settings.
Traceback (most recent call last):
File "C:/Users/danie/PycharmProjects/Web_Scraping_Project/Web_Scraper.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Process finished with exit code 1
You have to activate the virtual environment.
source venv/bin/activate
pip install requests
Or you can add the library, from the PyCharm GUI.
There is a "+" on the edit interpreter in settings in the, click on it and search for the requests library.
Seems as if your project is using a virtualenv python environment. The pip install you did is probably on your system wide python installation.
You can install packages by activating your virutalenv (source path/to/venv/bin/activate) and using pip as usual, installing packages using the PyCharm interface (you can see a litte "+" button in your screenshot) or just by using the terminal in PyCharm (this should activate the virtualenv automatically).

Python Virtualenv : ImportError: No Module named Zroya

I was trying to work with python virtualenv on the Zroya python wrapper around win32 API. Although I did installed the modules using pip, and although they are shown in cli using the command
pip freeze
,when trying to execute the .py file that uses the modules it shows the following error.
Traceback (most recent call last):
File "TesT.PY", line 2, in <module>
from zroya import NotificationCenter
ImportError: No module named 'zroya'
What is the reason for this cause ? I'm using python 3.4. When checked on
>>>help("modules")
on python cli, the modules that were installed using pip aren't listed.
Your virtualEnv is separate from OS Python environment.
Check whether you installed 'zroya' module in OS Python env or virtualEnv.
Run bin/activate in your virtual env, and check if 'zroya' module exists
>>>help("modules")
If no module named Zroya, run install command pip install xxx after activating virtual env.
Installing zroya should solve your problem.
Installation instructions: https://pypi.python.org/pypi/zroya
There seems to be some issue with the pip install. Copying the zroya directory from github repository over to PYTHONPATH resolved the conflict.

python cannot find module that is installed on windows

I have installed the requests module
C:\Python34\Scripts\easy_install.exe requests
i got to the folder location
C:\Python34\Lib\site-packages\requests-2.13.0-py3.4.egg\requests
I have a path variable in system
C:\Python34\Lib\site-packages
yet when i run my script
C:\Users\beast\Desktop>update.py
I get the error No module named 'requests'
Traceback (most recent call last):
File "C:\Users\beast\Desktop\plex_playlist_update.py", line 17, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
I tried installing using pip just in case
python -m pip install requests
Requirement already satisfied: requests in c:\python34\lib\site-packages\requests-2.13.0-py3.4.egg
I am new to python and I cant find an answer anywhere.
UPDATE:
I found a command to check my python search location.
C:\Users\beast\Desktop>python -c "import site; print(site.getsitepackages())"
['C:\\Python34', 'C:\\Python34\\lib\\site-packages']
I think it has to do with C:\Python34 vs C:\python34? How do i check or fix this?
The problem here is maybe because of the different versions of python installed.
If you are a Windows user, you can go to Path in Environment variables and remove the paths to unnecessary versions of python (if any). Modules installed for one version of python won't work in another version.
So I ended up going with python environment. Per python documentation it is the way to go anyway. The below command are run on the root folder of the python app.
py -m venv env
then
./env/Scripts/activate
I then ran my pip upgrade and everything is working. Obviously this did not fix it computer wide. just for my python app. But from documentation this is better because of version control of the whole enviroment.
This creates a "env" folder at the root which will have all the packages installed. Need to install all requirements again or use the requirements.txt file.

Categories