Pipenv could not find platform independent libraries <prefix> - python

Very weird problem. While python and works perfectly fine, I couldn't use pipenv.
I'm running it on windows, and it doesn't work on windows terminal, powershell, vscode terminal. Python version is 3.10.5, system PATH already has the folder location where python.exe is. I have also tried adding PYTHONPATH and PYTHONHOME variables but still did not work.
I'm still new at this, I tried pip uninstall pipenv, virtualenv, but when I run pipenv it still gives me the same error message and not the "not recognized as a command" error.
This is the error message when I run pipenv --version, pipenv shell, pipenv install etc.:
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'c:/program files/inkscape/bin/python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\program files\\inkscape\\bin\\python.exe'
sys.base_prefix = 'D:\\a\\_temp\\msys\\msys64\\mingw64'
sys.base_exec_prefix = 'C:\\program files\\inkscape'
sys.executable = 'C:\\program files\\inkscape\\bin\\python.exe'
sys.prefix = 'D:\\a\\_temp\\msys\\msys64\\mingw64'
sys.exec_prefix = 'C:\\program files\\inkscape'
sys.path = [
'D:\\a\\_temp\\msys\\msys64\\mingw64\\lib\\python38.zip',
'D:\\a\\_temp\\msys\\msys64\\mingw64\\lib\\python3.8',
'D:\\a\\_temp\\msys\\msys64\\mingw64\\lib\\python3.8',
'C:\\program files\\inkscape\\lib\\python3.8\\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 0x00006e4c (most recent call first):
<no Python frame>
I thought inkscape was the problem, so I uninstalled it, but it still doesn't work.
Please help me, thank you

I may not be able to answer your question but I might contribute to the solution:
1.try to find here why you get the ModuleNotFoundError: No module named 'encodings'
what library are you missing ?
2. Check this older thread here it may be of help : ImportError: No module named 'encodings'
3. I used to use Pipenv in my Jupiter terminal and due to colleagues engineering choices I always had problem so decided to move to Poetry check it out is really good :https://python-poetry.org/
I may have not helped you find the answer but hopefully have made a small contribution...all debugging is like criminal investigation sometimes you need to incrementally acquire new evidence to solve crimes so ..expect lots of patience from yourself and don't get disappointed easily!

This was the answer for me:
Long story short, I uninstalled the python from Microsoft Store, restarted my computer, installed using the python 3.10.5 installer from python.org, made sure I check the checkbox to “add python to PATH”, restart my computer. On the terminal, run “which python” and ensure it is on the right path, which should be “c:\users\ [username]\appdata\local\programs\python\python310\python” and not on “c:\program files\windowsapp....” This should be both on the user variable and system variable for the variable “PATH”
I consulted with a programmer friend and he helped me solve this issue.
This is the process for troubleshooting for anyone facing similar issues as I did on Windows:
Find which python, pip, and pipenv the system is using (different terminals like windows terminal, powershell, cmd prompt might have different results, so just use the one you like the most, which was for me was my modified windows terminal). The error code here only tells me the symptoms and not the actual problem. So pursuing the “encoding module not found” was actually jumping deeper into the rabbit hole. Luckily, I realized from experience that encoding was not the issue, but rather the terminal did not recognize where python or pipenv is. (I do realize that when a module or cmd is not recognized, the terminal will usually say “module not recognized” instead of the this long error prompt. So it is still a mistery to me why it did that instead of the simple “module not recognized”.
“Which python” shows the default python installation used, “python -V” shows which python it is associated with and the location, “pip show certifi” is for showing which python pip is using
I found a discrepancy, where most of my modules use appdata, which is where normally pip installs and python.org installers use. But python was using WindowsApp because I had installed it using microsoft store. (On my defense, when you google python installer most guides will tell you to install from microsoft store, which was a rookie mistake)
Uninstall the python you don’t want on “add or remove program” from windows. Then install python on its website and make sure to check the checkbox for adding the newly installed python to the system environment variable. See if it works on the terminal. Normally the computer needs to reboot to make the necessary changes.
Done! If it doesn’t work, make sure to purge every python you have on the computer, install using the installer directly from the python website, and make sure the python path is added to the environment variable

Related

PyInstaller: ModuleNotFoundError: No module named 'encodings'

I have a GUI application made using PySide2 and it some major modules it uses are OpenVino(2019), dlib, OpenCV-contrib(4.2.x) and Postgres(psycopg2) and I am trying to freeze the application using PyInstaller (--debug is True).
The program gets frozen without errors but during execution, I get the following error:
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
after which the application exits.
I have tried many suggestions provided in other stackoverflow questions/github issues but none of them have worked.
I have python version 3.7.6 but I have also tried with 3.6.8 (both local installation and after creating new venv in pycharm). I have tried different versions of pycharm as well(it shows som other errors below 3.5). I have tried pycharm 3.6 both develop branch and master branch.
I have checked my PYTHONPATH and PYTHONHOME in env variables, they are pointing to python's location.
I have modified my specfile to include the necessary binaries, files, imports and folders. I would share it if needed. Also any other logs during build or execution.
I would like to know what I should do to solve this, wheather this issue is because of some component or is this a PyInstaller issue, and if so, should I raise it on github.
My os is windows 10.
You changed the python version. So, you have to give a new path according to the Python version.
Just remove all older version and the current one and reinstall new Python v.3.8.1
You need to include base_library.zip in your application folder

ImportError: No module named site - mac

I have had this problem for months. every time that I want to get a new python package and use it I get this error in terminal:
ImportError: No module named site
I don't know why do I get this error. actually, I can't use any new package because every time that I wanna install one I get this error. I searched and I found out that the problem would be for PYTHONPATH and PYTHONHOME but I don't know what they are and how can I change them.
My operating system is mac os and I don't know how to solve this problem in mac.
every time that I open the terminal I use these two commands to solve the problem:
unset PYTHONHOME
unset PYTHONPATH
but the next time I get the error again.
The Python tooling is evolving in Mac OS X such that Python 2.7 is being deprecated. System default paths may no longer apply as I learned after upgrading to Mac OS X Catalina (10.15.x). There are a few scenarios here:
GENERIC FIX -- According to this primer on the site package and Python internal paths, Python 2.7 requires a specific user path for site packages. The solution I settled on was simply this:
mkdir -p ~/.local/lib/python2.7/site-packages
At that point you will have a dedicated directory for Python modules (for Python to function). (NOTE that the error ImportError: No module named site is misleading as it really indicates that the correct directory structure didn't exist to allow the site module to properly load.)
BASIC ALTERNATIVE -- Is your PYTHONHOME pointing to Python3 and your python --version reporting 2.7? Does python3 --version report something different (or work at all)? This error started happening for me after the Catalina upgrade when I was trying to use built-ins. Check your .profile and .bash_profile to see if they are explicitly setting a custom PYTHONHOME and/or PYTHONPATH. One option is to change that so the ENV variables are set explicitly and manually only when a newer Python is needed. You may consider symlinking python3 and pip3 to leave the standard commands to the OS.
DEBUGGING -- If you would like to test and/or get more information, try executing Python in one of the increasingly verbose modes:
python -v
python -vv
python -vvv

ImportError: No module named 'resource'

I am using python 3.5 and I am doing Algorithms specialization courses on Coursera. Professor teaching this course posted a program which can help us to know the time and memory associated with running a program. It has import resource command at the top. I tried to run this program along with the programs I have written in python and every time I received ImportError: No module named 'resource'
I used the same code in ubuntu and have no errors at all.
I followed suggestions in stackoverflow answers and I have tried adding PYTHONPATH PYTHONHOME and edited the PATH environment variable.
I have no idea of what else I can do here.
Is there any file that I can download and install it in the Lib or site-packages folder of my python installation ?
resource is a Unix specific package as seen in https://docs.python.org/2/library/resource.html which is why it worked for you in Ubuntu, but raised an error when trying to use it in Windows.
I ran into similar error in window 10. Here is what solved it for me.
Downgrade to the Apache Spark 2.3.2 prebuild version
Install (or downgrade) jdk to version 1.8.0
My installed jdk was 1.9.0, which doesn't seem to be compatiable with spark 2.3.2 or 2.4.0
make sure that when you run java -version in cmd (command prompt), it show java version 8. If you are seeing version 9, you will need to change your system ENV PATH to ensure it points to java version 8.
Check this link to get help on changing the PATH if you have multiple java version installed.
Hope this helps someone, I was stuck on this issue for almost a week before finally finding a solution.

SCons ImportError - No module named SCons.Script‏

I have been trying to get SCons working now for quite a time, but didn't succeed yet. Before everything else: I'm running Windows 7 x64.
I have firstly installed Python 2.7.11 in C:\Software\Python27 and added both that directory as C:\Software\Python\Scripts to
the system path (for all users, that is). Then I installed SCons in C:\Software\Python27\Lib\site-packages\scons-2.4.1, and
the scripts in the previous mentioned scripts-directory (the directories which the SCons installation msi defaults to).
And now when I try to run SCons I get this error message:
Import failed. Unable to find SCons files in:
...
ImportError: No module named SCons.Script
As a user I really don't have any idea where the error comes from, other than that SCons can't resolve it's own imports.
I got it working by creating though by creating a new folder: C:\Software\Python27\Scripts\scons-local and moving the
contents of the SCons installation folder (...\Python27\Lib\site-packages\scons-2.4.1) to the newly created folder. But this
gives me a syntax error:
I found here that this error is due to my Python version not supporting conditional expressions, because this kind of
expressions are supported from Python 2.4 and higher. The thing is though that I am using Python 2.7.11, and thus I shouldn't get
this error.
Some help would be highly appreciated, thanks in advance!
The windows installer is no longer supported.
The best way to install SCons is now via pip
so:
python -Mpip install SCons
Note you will need Python 3.5 or newer (though at this point I'd suggest 3.10 or newer)

Which python... file directory PIP

I am sure on my Mac 0SX 10.9 I have more than one version of Python 2.7.5.
When I type in
which python
in the terminal, I get /Library/Frameworks/Python.framework/Versions/2.7/bin/python
When I am doing a pip.install it seems those are loading in a different path, they are all under /Library/Python/2.7/site-packages.
When I am in IDLE or my IDE (Sypder) and type
import sys
print sys.path
I get lots and lots of paths that start with /Library/Python/2.7/site-packages.
My problem is when I do a help() or import() on one of the modules I can see in /Library/Python/2.7/site-packages, I get a NameError: name 'Module' is not defined. Examples that I can see loaded in .../site.packages are pandas, nympy, and PyMySQL. But all give me "name of module not found".
Ideal python distribution control on a Mac: use a (free) scientific python environment like Enthought or Anaconda, and use either the real virtualenv package or the provided virtualenv package to control 'virtual environments' in which you can install packages. Virtualenvs really help keep the python distribution clean.
Good Luck.
Python development on a Mac can be a pain in the butt. That's why I set up a Arch Linux through Virtual Box and I'm quite happy with it. However, iOS development with Python using Kivy requires XCode (as far as I know) to deploy the apps on the iOS devices. So I'm in the same boot as you are.
Long story short: Running brew doctor (as in homebrew) in the terminal helped me a lot cleaning up my Python installations on the Mac.

Categories

Resources