0

I apologize if this question has been answered in a different thread, I have been looking everywhere for the last week but couldn't find anything that is specific to my case.

I created a .py program that is working as expected, however the moment that I try to convert it into an exe, it starts to generate the following error: File "site-package\six.py", line82, in _import_module ImportError: No module named urllib2

I understand that the six module was made to facilitate running the code whether using python 2 or 3 and I also understand that urllib2 has been split into request and error.

I went through the six.py file to check references of urllib2 but I am not sure what kind of modification I need to make, I am kind of new to Python.

I tried this in python 2.7.10 and python 3.4 and I really don't understand what I am missing. i also tried pyinstaller and py2exe and got the same error message.

I didn't include the code I wrote because the error is coming from the six.py file itself.

Any help that you can provide me to fix this is greatly appreciated.

Thank you!

Intidhar

Intidhar
  • 1
  • 1

1 Answers1

0

Sometimes python can't see modules in site-packages (or dist-packages in *nix) folder. Especially when you try to use generator (like py2exe) or use python interpreter as zip-package.

Your module six in site-package folder, but urllib2 is not. I have solved my (similar) problem with copying all modules from site-packages to top-level (site-packages/..) folder.

P.S. I know, it is a bad way, but you can do it with your copy of interpreter.

Alexey Astahov
  • 203
  • 1
  • 7
  • Thank you Alexey for suggesting this, I already tried it by copying six.py from the site packages folder to the pyton34\Lib directory but I received the same error. Additionally, I don't have urllib2 anywhere since I have python 3. – Intidhar Feb 11 '16 at 14:12
  • *This answer is for python3* => It can means that your six.py runs in python2 mode (instead of python3 mode). here http://stackoverflow.com/questions/2792650/python3-error-import-error-no-module-name-urllib is explanation of this exception. And here https://pythonhosted.org/six/#package-contents you can see flags for python2 or 3 mode. Check this flags in your six.py and try to make them for Py3. *For python2* => you should have urllib2 cause it is a standart module – Alexey Astahov Feb 12 '16 at 11:23