PyWin32 (226) and virtual environments - python

[PyPI]: pywin32 226 has been released on 20191110. It works on most of the Python installations (e.g. works on the official versions downloaded from Python), but not on virtual environments (e.g. created with VirtualEnv (v16.7.7), and (based on further research) Python's venv). I used Python v3.8.0 and v3.7.3 as lab rats. Here's the output for the former:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058805040]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe" -c "import win32api"
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py", line 769, in <module>
main()
File "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py", line 746, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py", line 279, in addsitepackages
addsitedir(sitedir, known_paths)
File "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py", line 202, in addsitedir
addpackage(sitedir, name, known_paths)
File "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site.py", line 170, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\lib\site-packages\win32\lib\pywin32_bootstrap.py", line 14, in <module>
for maybe in site.getsitepackages():
AttributeError: partially initialized module 'site' has no attribute 'getsitepackages' (most likely due to a circular import)

Note: I branched this answer (and also the question) from [SO]: PyWin32 and Python 3.8.0 (#CristiFati's answer), as it's a different issue. You might want to check that one before going further.
After some digging, it turns out it's a VirtualEnv bug (or at least, that's how I see things, because VirtualEnv's site.py doesn't contain getsitepackages - although it was present in Python's site.py since v2.7). There are several issues (that were) open revolving this absence (e.g. [GitHub]: pypa/virtualenv - site.getsitepackages() missing), but they appear to be closed without a fix (many of them due to inactivity). Also, [GitHub]: [WIP] The next-gen virtualenv (rewrite) which is a big refactor, doesn't seem to address it.
Recap: this error (in VirtualEnv context):
Also applies to other Python versions (I can confirm for v3.7.3 (32bit))
Happens every time when the interpreter starts
In conclusion, do not install PyWin32 226 in (VirtualEnv) virtual environments, as they will end up in a broken state!
PyWin32 (official .whls) "compatibility table" (didn't check Anaconda (or other such tools)):
"Normal" (official) Python installations:
v226 is OK
VirtualEnvs (and also Python's standard venvs):
v225 is OK
For Python 3.8.0, [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 should be used
Submitted [GitHub]: mhammond/pywin32 - Workaround for virtual environments (VirtualEnv) (merged on 20191114). Applying the changes locally (check the referenced question for details on how to do it), fixed it:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058805040]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> ".\venv_py_064_030800\Scripts\python.exe" -m pip list
Package Version
---------- -------
pip 19.3.1
pywin32 226
setuptools 41.6.0
wheel 0.33.6
[prompt]> ".\venv_py_064_030800\Scripts\python.exe" -c "import win32api"
[prompt]>
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!

Related

i tried to install pyinstaller with pip install pyinstaller and got this: [duplicate]

I just installed Python 3.6.1 for MacOS X
When I attempt to run the Console(or run anything with Python3), this error is thrown:
AttributeError: module 'enum' has no attribute 'IntFlag'
$ /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
The class IntFlag exists within enum.py. So, why is the AttributeError being thrown?
It's because your enum is not the standard library enum module. You probably have the package enum34 installed.
One way check if this is the case is to inspect the property enum.__file__
import enum
print(enum.__file__)
# standard library location should be something like
# /usr/local/lib/python3.6/enum.py
Since python 3.6 the enum34 library is no longer compatible with the standard library. The library is also unnecessary, so you can simply uninstall it.
pip uninstall -y enum34
If you need the code to run on python versions both <=3.4 and >3.4, you can try having enum-compat as a requirement. It only installs enum34 for older versions of python without the standard library enum.
Not sure whether you still have this issue. I had a similar issue and I was able to resolve it simply by unsetting PYTHONPATH
$ unset PYTHONPATH
For me this error occured after installing of gcloud component app-engine-python in order to integrate into pycharm. Uninstalling the module helped, even if pycharm is now not uploading to app-engine.
If anyone coming here because of getting this error while running a google app engine Python 3.7 standard environment project in PyCharm then all you need to do is
Make sure the configuration to run is for Flask, not Google App Engine configuration.
Then disable Google App Engine support under Preferences >> Languages & Framework >> Google App Engine
The reason being as per this link
The overall goal is that your app should be fully portable and run in any standard Python environment. You write a standard Python app, not an App Engine Python app. As part of this shift, you are no longer required to use proprietary App Engine APIs and services for your app's core functionality. At this time, App Engine APIs are not available in the Python 3.7 runtime.
I guess when we create a python 3.7 project in PyCharm as a Google app engine project it still tries to do the same way it does for a python2.7 app
I got this issue while installing transformers library from HuggingFace. It was due to the fact package enum34 was installed in my environment which was overriding built-in enum in Python. This package was probably installed by something as for forward compatibility which is no longer needed with Python 3.6+. So the solution is simply,
pip uninstall -y enum34
DISCLAIMER: Please, #juanpa.arrivillaga, if you see this answer, feel free to write your own and I will remove this post.
#juanpa.arrivillaga had mentioned above:
Is there a file name enum.py in your working directory, by any chance?
This was the issue I encountered. I was not aware of the enum module on python at the time and had named my test file enum.py.
Since the file name is the module name, there was a conflict. More info on modules here: https://docs.python.org/2/tutorial/modules.html
Installing version 1.1.8 of enum34 worked for me.
I was able to fix this by adding enum34 = "==1.1.8" to pyproject.toml.
Apparently enum34 had a feature in v1.1.8 that avoided this error, but
this regressed in v1.1.9+. This is just a workaround though. The
better solution would be for packages to use environment markers so
you don't have to install enum34 at all unless needed.
Source: https://github.com/python-poetry/poetry/issues/1122
Disabling "Google App Engine Support" in pycharm preferences fixed this issue for me.
Håken Lid's answer helped solved my problem (thanks!) , in my case present in Python3.7 running Flask in a Docker container (FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7).
In my case, enum34 was being installed by another library (pip install smartsheet-python-sdk).
For those coming with a similar Docker container problem, here is my final Dockerfile (stripped to the relevant lines):
FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7
...
RUN pip install -r requirements.txt
RUN pip uninstall -y enum34
...
In case you have to keep PYTHONPATH for both python2 and python3, you can write alias statements to set the proper PYTHONPATH in your bash_profile:
Hardcode your PYTHONPATH2, and PYTHONPATH3 variables in your ~/.bash_profile, and add the following aliases at the end of it:
alias python='export PYTHONPATH=${PYTHONPATH2};python'
alias python3='export PYTHONPATH=${PYTHONPATH3};python3'
My python (refers to python2) as I use python2 more often.
I have Python 2 and Python 3 installed on my computer. For some strange reason I have in the sys.path of Python 3 also a path to the sitepackage library directory of Python2 when the re module is called. If I run Python 3 and import enum and print(enum.__file__) the system does not show this Python 2 path to site-packages. So a very rough and dirty hack is, to directly modify the module in which enum is imported (follow the traceback paths) and insert the following code just before importing enum:
import sys
for i, p in enumerate(sys.path):
if "python27" in p.lower() or "python2.7" in p.lower(): sys.path.pop(i)
import enum
That solved my problem.
When ever I got this problem:
AttributeError: module 'enum' has no attribute 'IntFlag'
simply first i run the command:
unset PYTHONPATH
and then run my desired command then got success in that.
I did by using pip install <required-library> --ignore-installed enum34
Once your required library is installed, look for warnings during the build.
I got an Error like this:
Using legacy setup.py install for future, since package 'wheel' is not installed
ERROR: pyejabberd 0.2.11 has requirement enum34==1.1.2, but you'll have enum34 1.1.10 which is incompatible.
To fix this issue now run the command: pip freeze | grep enum34. This will give you the version of the installed enum34. Now uninstall it by pip uninstall enum34 and reinstall the required version as pip install "enum34==1.1.20"
If you having this issue when running tests in PyCharm, make sure the second box is unchecked in the configurations.
I had this problem in ubuntu20.04 in jupyterlab in my virtual env kernel with python3.8 and tensorflow 2.2.0. Error message was
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/home/hu-mka/.local/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
from .core.application import Application
File "/home/hu-mka/.local/lib/python2.7/site-packages/IPython/core/application.py", line 23, in <module>
from traitlets.config.application import Application, catch_config_error
File "/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/__init__.py", line 1, in <module>
from .traitlets import *
File "/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 49, in <module>
import enum
ImportError: No module named enum
problem was that in symbolic link in /usr/bin/python was pointing to python2. Solution:
cd /usr/bin/
sudo ln -sf python3 python
Hopefully Python 2 usage will drop off completely soon.
Even I had this issue while running python -m grpc_tools.protoc --version
Had to set the PYTHONPATH till site-packages and shutdown all the command prompt windows and it worked. Hope it helps for gRPC users.
Unfortunately none of the suggestions helped me, but after some more googling this
pip install aenum
solved it for me
I faced the same issue, but I couldn't change the environment the script is run inside. So the fixes here were not applicable for me.
What I did instead was
import os
import sys
os.environ["PYTHONPATH"] = os.pathsep.join(
(p for p in os.environ["PYTHONPATH"].split(os.pathsep) if "python2" not in p)
)
sys.path = [p for p in sys.path if "python2" not in p]
# Now that the paths are clean, we can import re
import re
2022 UPDATE
If you are using a modern version of Python (in my case 3.9.x), you don't need "enum34" at all, as this library is described as "Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4"
So in my case, the solution was to get rid of it entirely:
pip uninstall enum34
Now Pycharm runs my app perfectly.
My problem was that I marked a directory of mine as a Test Sources Root in pycharm which caused the python ast package to look for enum within <my_test_src_root_dir>/__init__.py (which was empty). I found this by clicking on the line that threw and then controlling (mac CMD-B) into the enum package and seeing that it went to the __init__.py file of the marked directory.
The file that threw:
"/opt/homebrew/Cellar/python#3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ast.py"
The line that threw:
from enum import IntEnum, auto
The error:
ImportError: cannot import name 'IntEnum' from 'enum' (.../path/to/_init_.py)
If anyone is having this problem when trying to run Jupyter kernel from a virtualenv, just add correct PYTHONPATH to kernel.json of your virtualenv kernel (Python 3 in example):
{
"argv": [
"/usr/local/Cellar/python/3.6.5/bin/python3.6",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3 (TensorFlow)",
"language": "python",
"env": {
"PYTHONPATH": "/Users/dimitrijer/git/mlai/.venv/lib/python3.6:/Users/dimitrijer/git/mlai/.venv/lib/python3.6/lib-dynload:/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6:/Users/dimitrijer/git/mlai/.venv/lib/python3.6/site-packages"
}
}
ensure there is no file or folder named enum in your codebase

Instaling airflow on python virtual environment [duplicate]

I just installed Python 3.6.1 for MacOS X
When I attempt to run the Console(or run anything with Python3), this error is thrown:
AttributeError: module 'enum' has no attribute 'IntFlag'
$ /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
The class IntFlag exists within enum.py. So, why is the AttributeError being thrown?
It's because your enum is not the standard library enum module. You probably have the package enum34 installed.
One way check if this is the case is to inspect the property enum.__file__
import enum
print(enum.__file__)
# standard library location should be something like
# /usr/local/lib/python3.6/enum.py
Since python 3.6 the enum34 library is no longer compatible with the standard library. The library is also unnecessary, so you can simply uninstall it.
pip uninstall -y enum34
If you need the code to run on python versions both <=3.4 and >3.4, you can try having enum-compat as a requirement. It only installs enum34 for older versions of python without the standard library enum.
Not sure whether you still have this issue. I had a similar issue and I was able to resolve it simply by unsetting PYTHONPATH
$ unset PYTHONPATH
For me this error occured after installing of gcloud component app-engine-python in order to integrate into pycharm. Uninstalling the module helped, even if pycharm is now not uploading to app-engine.
If anyone coming here because of getting this error while running a google app engine Python 3.7 standard environment project in PyCharm then all you need to do is
Make sure the configuration to run is for Flask, not Google App Engine configuration.
Then disable Google App Engine support under Preferences >> Languages & Framework >> Google App Engine
The reason being as per this link
The overall goal is that your app should be fully portable and run in any standard Python environment. You write a standard Python app, not an App Engine Python app. As part of this shift, you are no longer required to use proprietary App Engine APIs and services for your app's core functionality. At this time, App Engine APIs are not available in the Python 3.7 runtime.
I guess when we create a python 3.7 project in PyCharm as a Google app engine project it still tries to do the same way it does for a python2.7 app
I got this issue while installing transformers library from HuggingFace. It was due to the fact package enum34 was installed in my environment which was overriding built-in enum in Python. This package was probably installed by something as for forward compatibility which is no longer needed with Python 3.6+. So the solution is simply,
pip uninstall -y enum34
DISCLAIMER: Please, #juanpa.arrivillaga, if you see this answer, feel free to write your own and I will remove this post.
#juanpa.arrivillaga had mentioned above:
Is there a file name enum.py in your working directory, by any chance?
This was the issue I encountered. I was not aware of the enum module on python at the time and had named my test file enum.py.
Since the file name is the module name, there was a conflict. More info on modules here: https://docs.python.org/2/tutorial/modules.html
Installing version 1.1.8 of enum34 worked for me.
I was able to fix this by adding enum34 = "==1.1.8" to pyproject.toml.
Apparently enum34 had a feature in v1.1.8 that avoided this error, but
this regressed in v1.1.9+. This is just a workaround though. The
better solution would be for packages to use environment markers so
you don't have to install enum34 at all unless needed.
Source: https://github.com/python-poetry/poetry/issues/1122
Disabling "Google App Engine Support" in pycharm preferences fixed this issue for me.
Håken Lid's answer helped solved my problem (thanks!) , in my case present in Python3.7 running Flask in a Docker container (FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7).
In my case, enum34 was being installed by another library (pip install smartsheet-python-sdk).
For those coming with a similar Docker container problem, here is my final Dockerfile (stripped to the relevant lines):
FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7
...
RUN pip install -r requirements.txt
RUN pip uninstall -y enum34
...
In case you have to keep PYTHONPATH for both python2 and python3, you can write alias statements to set the proper PYTHONPATH in your bash_profile:
Hardcode your PYTHONPATH2, and PYTHONPATH3 variables in your ~/.bash_profile, and add the following aliases at the end of it:
alias python='export PYTHONPATH=${PYTHONPATH2};python'
alias python3='export PYTHONPATH=${PYTHONPATH3};python3'
My python (refers to python2) as I use python2 more often.
I have Python 2 and Python 3 installed on my computer. For some strange reason I have in the sys.path of Python 3 also a path to the sitepackage library directory of Python2 when the re module is called. If I run Python 3 and import enum and print(enum.__file__) the system does not show this Python 2 path to site-packages. So a very rough and dirty hack is, to directly modify the module in which enum is imported (follow the traceback paths) and insert the following code just before importing enum:
import sys
for i, p in enumerate(sys.path):
if "python27" in p.lower() or "python2.7" in p.lower(): sys.path.pop(i)
import enum
That solved my problem.
When ever I got this problem:
AttributeError: module 'enum' has no attribute 'IntFlag'
simply first i run the command:
unset PYTHONPATH
and then run my desired command then got success in that.
I did by using pip install <required-library> --ignore-installed enum34
Once your required library is installed, look for warnings during the build.
I got an Error like this:
Using legacy setup.py install for future, since package 'wheel' is not installed
ERROR: pyejabberd 0.2.11 has requirement enum34==1.1.2, but you'll have enum34 1.1.10 which is incompatible.
To fix this issue now run the command: pip freeze | grep enum34. This will give you the version of the installed enum34. Now uninstall it by pip uninstall enum34 and reinstall the required version as pip install "enum34==1.1.20"
If you having this issue when running tests in PyCharm, make sure the second box is unchecked in the configurations.
I had this problem in ubuntu20.04 in jupyterlab in my virtual env kernel with python3.8 and tensorflow 2.2.0. Error message was
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/home/hu-mka/.local/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
from .core.application import Application
File "/home/hu-mka/.local/lib/python2.7/site-packages/IPython/core/application.py", line 23, in <module>
from traitlets.config.application import Application, catch_config_error
File "/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/__init__.py", line 1, in <module>
from .traitlets import *
File "/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 49, in <module>
import enum
ImportError: No module named enum
problem was that in symbolic link in /usr/bin/python was pointing to python2. Solution:
cd /usr/bin/
sudo ln -sf python3 python
Hopefully Python 2 usage will drop off completely soon.
Even I had this issue while running python -m grpc_tools.protoc --version
Had to set the PYTHONPATH till site-packages and shutdown all the command prompt windows and it worked. Hope it helps for gRPC users.
Unfortunately none of the suggestions helped me, but after some more googling this
pip install aenum
solved it for me
I faced the same issue, but I couldn't change the environment the script is run inside. So the fixes here were not applicable for me.
What I did instead was
import os
import sys
os.environ["PYTHONPATH"] = os.pathsep.join(
(p for p in os.environ["PYTHONPATH"].split(os.pathsep) if "python2" not in p)
)
sys.path = [p for p in sys.path if "python2" not in p]
# Now that the paths are clean, we can import re
import re
2022 UPDATE
If you are using a modern version of Python (in my case 3.9.x), you don't need "enum34" at all, as this library is described as "Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4"
So in my case, the solution was to get rid of it entirely:
pip uninstall enum34
Now Pycharm runs my app perfectly.
My problem was that I marked a directory of mine as a Test Sources Root in pycharm which caused the python ast package to look for enum within <my_test_src_root_dir>/__init__.py (which was empty). I found this by clicking on the line that threw and then controlling (mac CMD-B) into the enum package and seeing that it went to the __init__.py file of the marked directory.
The file that threw:
"/opt/homebrew/Cellar/python#3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ast.py"
The line that threw:
from enum import IntEnum, auto
The error:
ImportError: cannot import name 'IntEnum' from 'enum' (.../path/to/_init_.py)
If anyone is having this problem when trying to run Jupyter kernel from a virtualenv, just add correct PYTHONPATH to kernel.json of your virtualenv kernel (Python 3 in example):
{
"argv": [
"/usr/local/Cellar/python/3.6.5/bin/python3.6",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3 (TensorFlow)",
"language": "python",
"env": {
"PYTHONPATH": "/Users/dimitrijer/git/mlai/.venv/lib/python3.6:/Users/dimitrijer/git/mlai/.venv/lib/python3.6/lib-dynload:/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6:/Users/dimitrijer/git/mlai/.venv/lib/python3.6/site-packages"
}
}
ensure there is no file or folder named enum in your codebase

Segmentation fault with Python with install of PyICU

I have been trying to install a Python library called Polyglot, which in turn requires PyICU, the source of my woes. After a wild goose chase of errors, I was able to install PyICU on my EC2 instance. However, when running Polyglot, and in turn PyICU, I get the following error:
Traceback (most recent call last):
File "/mnt/data/anaconda3/bin/polyglot", line 11, in <module>
load_entry_point('polyglot==16.7.4', 'console_scripts', 'polyglot')()
File "/mnt/data/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 487, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/mnt/data/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2728, in load_entry_point
return ep.load()
File "/mnt/data/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2346, in load
return self.resolve()
File "/mnt/data/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2352, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/mnt/data/anaconda3/lib/python3.6/site-packages/polyglot/__main__.py", line 16, in <module>
from icu import Locale
File "/mnt/data/anaconda3/lib/python3.6/site-packages/icu/__init__.py", line 37, in <module>
from _icu import *
ImportError: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /home/linuxbrew/.linuxbrew/lib/libstdc++.so.6)
To resolve the above issue, I performed the following steps:
mkdir ~/glibc_install; cd ~/glibc_install
wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz
tar zxvf glibc-2.18.tar.gz
cd glibc-2.18
mkdir build
cd build
../configure --prefix=/opt/glibc-2.18
make -j4
make install
export LD_LIBRARY_PATH=/opt/glibc-2.18/lib
But then when I simply ran Python, I got an immediate segmentation fault.
Note that I am using Red Hat 7.1.2-2 on an AWS EC2.
Any help at all would be most appreciated!
If you just want to experiment, you could use the beta of Red Hat Enterprise Linux 8, which comes with glibc 2.28 and therefore provides the GLIBC_2.18 symbols.
The segmentation fault will go away if you run Python with an explicitly loader invocation (such as /opt/glibc-2.18/lib64/ld-linux-x86-64.so.2 python …). If you want go into this direction, you should really use a more recent version of glibc still maintained upstream (such as glibc 2.28 at this time), and ideally a release branch from Git because it has many backports to fix various bugs.
But the next problem is that you are trying to replace the system libstdc++ library with a custom copy. This can break system software and third-party applications.
You should try to get a copy of the software you are trying to install that has been built for Red Hat Enterprise Linux 7 (or even Red Hat Enterprise Linux 6). It will be much easier to use, and avoid all these issues. If the software is written using a newer C++ standard than C++98, you can use Developer Toolset. It has a hybrid linking model, statically linking support code needed for newer C++ standard, while still using the system libstdc++ for the rest, to maximize interoperability.

Using a later version of six than 1.4.1 when running a python script

Trying to use the google api client, I have gotten an error that MANY others have gotten:
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlencode'
I have tried every solution found in StackOverflow, GitHub, and other places, including:
1) from this thread, changing the path in the actual code:
import sys
sys.path.insert(1, '/Library/Python/2.7/site-packages')
2) from this thread, changing the python path in the .bashrc and .bash_profile files:
pip show six | grep "Location:" | cut -d " " -f2
export PYTHONPATH=$PYTHONPATH:<pip_install_path>
source ~/.bashrc
3) and from this thread, downgrading my google api client to 1.3.2 (or at least trying to).
I'm new to programming so this could be a basic problem but I've spent days trying to troubleshoot and to no avail. It seems like no matter what I do, the old 1.4 version of six is being used. Any help you could provide would be MUCH appreciated!
EDIT: Full Traceback:
Traceback (most recent call last):
File "/Users/zachgoldfine/PycharmProjects/FirstTry/GetAroundRentalSpreadsheetRead.py", line 71, in <module>
spreadsheetId=spreadsheetId, range=rangeName1).execute()
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 129, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/googleapiclient/http.py", line 836, in execute
method=str(self.method), body=self.body, headers=self.headers)
File "/Library/Python/2.7/site-packages/googleapiclient/http.py", line 162, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/transport.py", line 186, in new_request
credentials._refresh(orig_request_method)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 761, in _refresh
self._do_refresh_request(http)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 774, in _do_refresh_request
body = self._generate_refresh_request_body()
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 716, in _generate_refresh_request_body
body = urllib.parse.urlencode({
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlencode'
Assuming it's indeed a problem with the six version, here is one way to install six and be able to use the newly installed version.
Important note: this will only work from your user account; not from any other account.
On the safe side: this will not alter the system Python environment, that is, system scripts that may use Python will continue to use the older pip version.
Firstly, reverse the three steps above. In particular, manually altering sys.path in a script should really very rarely be necessary.
Then, use the --user option, which installs a local version, that Python (when run by that user) will automatically pick up first.
To make sure the Python executable you are using corresponds to the pip module and (later) the installed six module, use the following:
python -m pip install six --user
where python may be something slightly else, if you happen to not use the system Python (e.g., z/usr/local/bin/python, orpython3, etc).
There is no need forsudo` or similar.
If pip complains that the requirement is already up to date (it shouldn't, or you wouldn't have gotten the above problems), try:
python -m pip install six --user --upgrade --force
Once done, you can check $HOME/Library/Python/x.y/lib/python/site-packages to see if you see the correct version of six there. This is your local user Library directory, not the system one. x.y is probably 2.7, but do check that python is actually that version.
The problem may also be with the google api client. I don't know if that has a pip installation, but otherwise you could try something similar as for six:
python -m pip install <google-api-client> --user (--upgrade --force)

easy_install : ImportError: Entry point ('console_scripts', 'easy_install') not found

I used easy_install to install pip, pip to install django, virtualenv, and virtualenvwrapper.
I have just returned to it a few weeks later and django does not seem to work anymore, but more concerning is I can't start the process over again as easy_install is returning the following error:
Traceback (most recent call last):
File "/usr/bin/easy_install-2.7", line 10, in <module>
load_entry_point('setuptools==0.6c12dev-r88846', 'console_scripts', 'easy_install')()
File "/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point
File "/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2220, in load_entry_point
ImportError: Entry point ('console_scripts', 'easy_install') not found
After a good evening of hunting I am stumped as to how to resolve this.
You seem to have a version conflict; note the setuptools-0.6c11-py2.7.egg path, but the /usr/bin/easy_install-2.7 script wants to load 0.6c12dev-r88846 instead.
The latter is a development version; it has the revision number of a subversion repository embedded in the version (dev-r88846).
I suspect you have two python installations; one is the system version (in /System/Library and the other is installed with the python installer into /Library/, and the stub script in /usr/bin/ may be installed with the system python.
If so, there'll be another copy of the stub at /Library/Python/2.7/bin/easy_install-2.7, which should work correctly.
I had the same issue, eventually ended up running the 2.7.3 easy_install by
/opt/python2.7.3/bin/easy_install which worked fine

Categories

Resources