Pip3.6 cannot import name 'main'

I'm building openwrt for x86 target. My host system is Ubuntu 18.04 on KVM. When I build I get an error:

Traceback (most recent call last):
  File "/mnt/data/openwrt/staging_dir/hostpkg/bin/pip3.6", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

I've been trying various strategies to get around this issue, such as updating the host pip and removing the python3 from my build. However, I really need python3 in my build and the host pip is not the issue, the problem is as indicated in the staging_dir. I can run that version of pip3.6 and reproduce the error.

So how do I get around this one? Do I need to modify the version of python3, i.e. 3.5 or something else?


I don't know the exact answer.

I have had issues tho', when it comes to selecting "Languages" and BR failing. Adding after always seems to work.

Having said that..... hostpkg .... are the utilities that are use to build..... not "specifically for the router".... if I understand right.

Maybe you need a "make clean" .... and "make download"..... to force the hostpkg items to be rebuilt.... or similar.... not 1000% sure.... It could also be that adding the pip environment to your host OS is the fix.... but the error seems to indicate it's a local requirement in the BR.

If that is the case.... and it has been triggered by device package selection, then there is merit in assuming it would be taken care of.

Sometimes you have to look very closely at erroneous BR errors.... because further up the page..... you might see something like "ERROR: abcv2 selected but abcV1 already installed" etc. "make -j1 V=s"

Just a guess.... ( also the exact method you used to select python3 may help others )

my suggestion is upgrade pip itself with
'pip install --upgrade pip'

and then setuptools,
'pip install --upgrade setuptools'

and pypi
'pip install pypi --user'

and other likely modules from the output of 'pip list'

if you can't talk to the remote repo, get the .tar.gz source files yourself by using your browser to go to:

if you're using .tar.gz now, try the wheel packages

some danger: you can clobber your site-modules with python3 ./packagename.tar.gz
check out https://docs.python.org/3/using/cmdline.html

I went thru this dance today but I achieved 100% success in the end

1 Like

This seems to be a problem on the 18.06 branch with Python 3.6. I tried on a clean machine with the same results. I tried using master with Python 3.7 and that worked ok. I'm not sure if the build from master will meet my needs otherwise. Hopefully it does.

1 Like

I just want to give some general overall advice/tips for python on openWRT,

based on this article that came out this month on opensource.com and what've I've learned in the past week:

for python installed on an operating system which doesn't use python by default:

  • openWRT on mips/armv7/x86/whatever
  • Android on aarch64 or armv7

you are generally safe to hammer the site modules as root, because there are no other 'users' on these OSes and the operating system doesn't use or care about python.

However on your 'build system', that is your Ubuntu, your Fedora, your Solaris where you are building something as a gift for a openWRT or Android target ~

  • if you use GNOME or MATE, the OS has its own versions of python in /usr/lib, and these may be python 2 or python 3.
  • if you run all your pip commands as an ordinary user, you may not be able to overwrite/install to
    /usr/lib, /usr/lib64, or /usr/local/lib/python/site-packages

this may be good/by design, but including '--user' to the command line will install your python junk in
but then you have to amend your $PATH when working with python to find your junk there.

you can ask python what he thinks of himself with

  • python2 -c "import sys; print('\n'.join(sys.path))"
  • python3 -c "import sys; print('\n'.join(sys.path))"

But I recommend the opensource URL I posted above, if you are into python lately.

my favorite one-liner python2 trick:
cd /home/userid
python2 -m SimpleHTTPServer

KABOOM! one line plain http/no encryption webserver on port 8000, from the cwd. Ctrl+C to break it.
[ the python3 versions are giving me a bit of trouble ]

1 Like