ImportError: cannot import name 'main' whe

2019-07-25 01:56发布

问题:

I've been able to normally download python libraries for a while but this happened and I've gone through every solution but I think this is specific to my situation

I was trying to download beautiful soup, got an error that said something like it couldn't correctly load "egginfo.py" or something like that, which I found might be fixed by upgrading setuptools. I did so and got this:

D:\Python3_64\Scripts>pip install beautifulsoup
Traceback (most recent call last):
  File "d:\python3_64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python3_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python3_64\Scripts\pip.exe\__main__.py", line 5, in <module>

ImportError: cannot import name 'main'

Using easyinstall:

D:\Python3_64\Scripts>easy_install beautifulsoup
Searching for beautifulsoup
Reading https://pypi.python.org/simple/beautifulsoup/
Downloading 

https://pypi.python.org/packages/1e/ee/295988deca1a5a7accd783d0dfe14524867e31abb

05b6c0eeceee49c759d/BeautifulSoup-
3.2.1.tar.gz#md5=44656527ef3ac9874ac4d1c9f35f70ee
Best match: BeautifulSoup 3.2.1
Processing BeautifulSoup-3.2.1.tar.gz
Writing C:\Users\Owner\AppData\Local\Temp\easy_install-
iwb6x4a5\BeautifulSoup-3.2.1\setup.cfg
Running BeautifulSoup-3.2.1\setup.py -q bdist_egg --dist-dir 
C:\Users\Owner\AppData\Local\Temp\easy_install-iwb6x4a5\BeautifulSoup-
3.2.1\egg-dist-tmp-rtwdsovx
Traceback (most recent call last):
  File "d:\python3_64\lib\site-packages\setuptools\sandbox.py", line 154, in 
save_modules
    yield saved
  File "d:\python3_64\lib\site-packages\setuptools\sandbox.py", line 195, in 
setup_context
    yield
  File "d:\python3_64\lib\site-packages\setuptools\sandbox.py", line 250, in 
run_setup
    _execfile(setup_script, ns)
  File "d:\python3_64\lib\site-packages\setuptools\sandbox.py", line 44, in 
_execfile
    code = compile(script, filename, 'exec')
  File "C:\Users\Owner\AppData\Local\Temp\easy_install-
iwb6x4a5\BeautifulSoup-3.2.1\setup.py", line 22
    print "Unit tests have failed!"
                              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(int 
"Unit tests have failed!")?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python3_64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python3_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python3_64\Scripts\easy_install.exe\__main__.py", line 9, in 
<module>
  File "d:\python3_64\lib\site-packages\setuptools\command\easy_install.py", 
line 2312, in main
    **kw
  File "d:\python3_64\lib\site-packages\setuptools\__init__.py", line 129, 
in setup
    return distutils.core.setup(**attrs)
  File "d:\python3_64\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "d:\python3_64\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "d:\python3_64\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "d:\python3_64\lib\site-packages\setuptools\command\easy_install.py", 
line 412, in run
    self.easy_install(spec, not self.no_deps)
  File "d:\python3_64\lib\site-packages\setuptools\command\easy_install.py", 
line 673, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "d:\python3_64\lib\site-packages\setuptools\command\easy_install.py", 
line 699, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "d:\python3_64\lib\site-packages\setuptools\command\easy_install.py", 
    line 884, in install_eggs

I can no longer download Python libraries of any sort because of this.

I've tried:

-Deleting older versions of python

-upgrading setuptools

-using pip3

-installing with the --user flag

-running an elevated prompt and trying to install

-using easyinstall

-uninstalling and reinstalling python

All help appreciated.

回答1:

bs4 is for python3 and BeautifulSoup is for python2. You are trying to install the wrong package. Do

pip install bs4


回答2:

With pip upgrade, it worked for me 1. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 2. python get-pip.py



标签: python pip