PIP (Python) : ImportError: cannot import name _remove_dead_weakref
Asked Answered
Z

2

9

I am getting below error, I have search lot around but haven't been able to find a good fix- Please anyone who was getting this kind of error and resolved. please help.

File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
   "__main__", fname, loader, pkg_name)
 File "c:\python27\lib\runpy.py", line 72, in _run_code
   exec code in run_globals
 File "C:\python27\Tools\Scripts\pip.exe\__main__.py", line 5, in <module>
 File "c:\python27\lib\site-packages\pip\__init__.py", line 5, in <module>
   import logging
 File "c:\python27\lib\logging\__init__.py", line 26, in <module>
   import sys, os, time, cStringIO, traceback, warnings, weakref, collections
 File "c:\python27\lib\weakref.py", line 14, in <module>
   from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Zingg answered 8/3, 2018 at 6:37 Comment(5)
what you are importing ? which module ?Lieutenant
Not accepting answers that do answer your questions as solutions, can make users that are able to help you less eager to really help you. This is one such case.Kall
Can you please specify which module you are importing.Deliberation
I have the same issue, importing requestsRooke
Actually I came to know that from our IT team they just copy and paste the python from one user profile to mine. Now I ask them don't do the copy paste. and ask them to install Python and all supporting modules separately.Zingg
B
1

I'm pretty sure the reason for this error is how you're installing python and that you've most likely copied your installation from somewhere else .. or you're renaming folders .. or you've an invalid python installation in your environmental path.

If you're looking to copy the python folder about, don't install it 'for all users' .. just install it to your folder for your 'logged in user only'.

So your solution should be either

  1. install python again pointing to your location c:\python27 or
  2. install python using the 'install just for this user' .. then copy from it to your c:\python27 .. you might be interested in pipenv and virtualenv (google search for them)

Also, you can run pip using

python -m pip install <module_to_install>

This is the same as running

pip.exe install <module_to_install>

You could try using the full path for python to see if it runs pip ok. eg. c:\python27\python.exe -m pip install <module_to_install>

Bromate answered 21/5, 2018 at 20:8 Comment(1)
Yes, Actually I came to know that our IT team just copy and paste the python from one user profile to another. Now I ask them don't do the copy paste. instead of installation.Zingg
D
9

I have encountered the similar issue on my macOS X when I run lldb from the terminal. The error message is the following,

16:55 $ lldb
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 52, in <module>
    import weakref
File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref

The error message is quite similar with yours. This is what I solved on my macOS X.

$ brew list
...<many libraries>
python@  <The one has conflicted with my python3.6>

$ brew remove python@2 --ignore-dependencies
Uninstalling /usr/local/Cellar/python@2/2.7.14_3... (4,662 files, 82.8MB)

I think the problem is caused by the system installed python, which conflicts with personally installed python. After I removed my python2.7 and lldb works well. I hope it will give you some idea, although we are running on a different OS.


To manage different version of python, I recommend you to install pyenv, see here. It can easily switch the different versions of your python.

Dignity answered 1/5, 2018 at 9:12 Comment(1)
I had the same problem, but instead of uninstalling python i just unlinked it: brew unlink python@2Terrorism
B
1

I'm pretty sure the reason for this error is how you're installing python and that you've most likely copied your installation from somewhere else .. or you're renaming folders .. or you've an invalid python installation in your environmental path.

If you're looking to copy the python folder about, don't install it 'for all users' .. just install it to your folder for your 'logged in user only'.

So your solution should be either

  1. install python again pointing to your location c:\python27 or
  2. install python using the 'install just for this user' .. then copy from it to your c:\python27 .. you might be interested in pipenv and virtualenv (google search for them)

Also, you can run pip using

python -m pip install <module_to_install>

This is the same as running

pip.exe install <module_to_install>

You could try using the full path for python to see if it runs pip ok. eg. c:\python27\python.exe -m pip install <module_to_install>

Bromate answered 21/5, 2018 at 20:8 Comment(1)
Yes, Actually I came to know that our IT team just copy and paste the python from one user profile to another. Now I ask them don't do the copy paste. instead of installation.Zingg

© 2022 - 2024 — McMap. All rights reserved.