New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named optparse. #576

Open
biergaizi opened this Issue Mar 9, 2014 · 9 comments

Comments

Projects
None yet
7 participants
@biergaizi

biergaizi commented Mar 9, 2014

Many Python Programs depends on Virtualenv, but I can not get it works on Gentoo ~mips N32. As an example, it caused Firefox unbuildable.

But both Python 2 & 3 works well on the system, it seems some files are not copied/symlinked to the prefix correctly. /lib on N32 is not a symlink of /lib32 or /lib64, maybe it is the reason?

As a Pythonista, I don't know the actual reason...

➜  virtualenv-1.11.4  ./virtualenv.py test_virtualenv 
New python executable in test_virtualenv/bin/python2.7 
Not overwriting existing python script test_virtualenv/bin/python (you must use test_virtualenv/bin/python2.7) 
Installing setuptools, pip... 
  Complete output from command /tmp/virtualenv-1.11...ualenv/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip: 
  Traceback (most recent call last): 
  File "<string>", line 1, in <module> 
  File "/tmp/virtualenv-1.11.4/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/__init__.py", line 3, in <module> 
ImportError: No module named optparse 
---------------------------------------- 
...Installing setuptools, pip...done. 
Traceback (most recent call last): 
  File "./virtualenv.py", line 2338, in <module> 
    main() 
  File "./virtualenv.py", line 824, in main 
    symlink=options.symlink) 
  File "./virtualenv.py", line 992, in create_environment 
    install_wheel(to_install, py_executable, search_dirs) 
  File "./virtualenv.py", line 960, in install_wheel 
    'PIP_NO_INDEX': '1' 
  File "./virtualenv.py", line 902, in call_subprocess 
    % (cmd_desc, proc.returncode)) 
OSError: Command /tmp/virtualenv-1.11...ualenv/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1 
test_virtualenv 
├── bin 
│   ├── python -> python2.7 
│   ├── python2 -> python2.7 
│   └── python2.7 
├── include 
│   └── python2.7 -> /usr/include/python2.7 
├── lib 
│   └── python2.7 
│       ├── config -> /usr/lib32/python2.7/config 
│       ├── lib-dynload -> /usr/lib32/python2.7/lib-dynload 
│       └── site-packages 
└── lib32 
    └── python2.7 
        ├── _abcoll.py -> /usr/lib32/python2.7/_abcoll.py 
        ├── _abcoll.pyc 
        ├── abc.py -> /usr/lib32/python2.7/abc.py 
        ├── abc.pyc 
        ├── codecs.py -> /usr/lib32/python2.7/codecs.py 
        ├── codecs.pyc 
        ├── copy_reg.py -> /usr/lib32/python2.7/copy_reg.py 
        ├── copy_reg.pyc 
        ├── distutils 
        │   ├── distutils.cfg 
        │   └── __init__.py 
        ├── encodings -> /usr/lib32/python2.7/encodings 
        ├── fnmatch.py -> /usr/lib32/python2.7/fnmatch.py 
        ├── genericpath.py -> /usr/lib32/python2.7/genericpath.py 
        ├── genericpath.pyc 
        ├── lib-dynload 
        │   ├── readline.so -> /usr/lib32/python2.7/lib-dynload/readline.so 
        │   └── zlib.so -> /usr/lib32/python2.7/lib-dynload/zlib.so 
        ├── linecache.py -> /usr/lib32/python2.7/linecache.py 
        ├── linecache.pyc 
        ├── locale.py -> /usr/lib32/python2.7/locale.py 
        ├── no-global-site-packages.txt 
        ├── ntpath.py -> /usr/lib32/python2.7/ntpath.py 
        ├── orig-prefix.txt 
        ├── os.py -> /usr/lib32/python2.7/os.py 
        ├── os.pyc 
        ├── posixpath.py -> /usr/lib32/python2.7/posixpath.py 
        ├── posixpath.pyc 
        ├── re.py -> /usr/lib32/python2.7/re.py 
        ├── site.py 
        ├── site.pyc 
        ├── sre_compile.py -> /usr/lib32/python2.7/sre_compile.py 
        ├── sre_constants.py -> /usr/lib32/python2.7/sre_constants.py 
        ├── sre_parse.py -> /usr/lib32/python2.7/sre_parse.py 
        ├── sre.py -> /usr/lib32/python2.7/sre.py 
        ├── stat.py -> /usr/lib32/python2.7/stat.py 
        ├── stat.pyc 
        ├── types.py -> /usr/lib32/python2.7/types.py 
        ├── types.pyc 
        ├── UserDict.py -> /usr/lib32/python2.7/UserDict.py 
        ├── UserDict.pyc 
        ├── warnings.py -> /usr/lib32/python2.7/warnings.py 
        ├── warnings.pyc 
        ├── _weakrefset.py -> /usr/lib32/python2.7/_weakrefset.py 
        └── _weakrefset.pyc 

13 directories, 45 files 
@Ivoz

This comment has been minimized.

Show comment
Hide comment
@Ivoz

Ivoz Mar 9, 2014

Member

Not overwriting existing python script test_virtualenv/bin/python (you must use test_virtualenv/bin/python2.7)

What's the deal with this? Are you creating the virtualenv in a clean folder?

Member

Ivoz commented Mar 9, 2014

Not overwriting existing python script test_virtualenv/bin/python (you must use test_virtualenv/bin/python2.7)

What's the deal with this? Are you creating the virtualenv in a clean folder?

@biergaizi

This comment has been minimized.

Show comment
Hide comment
@biergaizi

biergaizi Mar 9, 2014

@Ivoz

Still got the error if it is a clean directory.

# python2 virtualenv.py test_virtualenv 
New python executable in test_virtualenv/bin/python2
Also creating executable in test_virtualenv/bin/python
Installing setuptools, pip...
  Complete output from command /tmp/virtualenv-1.11...rtualenv/bin/python2 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/virtualenv-1.11.4/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/__init__.py", line 3, in <module>
ImportError: No module named optparse
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "virtualenv.py", line 2338, in <module>
    main()
  File "virtualenv.py", line 824, in main
    symlink=options.symlink)
  File "virtualenv.py", line 992, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "virtualenv.py", line 960, in install_wheel
    'PIP_NO_INDEX': '1'
  File "virtualenv.py", line 902, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /tmp/virtualenv-1.11...rtualenv/bin/python2 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1

biergaizi commented Mar 9, 2014

@Ivoz

Still got the error if it is a clean directory.

# python2 virtualenv.py test_virtualenv 
New python executable in test_virtualenv/bin/python2
Also creating executable in test_virtualenv/bin/python
Installing setuptools, pip...
  Complete output from command /tmp/virtualenv-1.11...rtualenv/bin/python2 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/virtualenv-1.11.4/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/__init__.py", line 3, in <module>
ImportError: No module named optparse
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "virtualenv.py", line 2338, in <module>
    main()
  File "virtualenv.py", line 824, in main
    symlink=options.symlink)
  File "virtualenv.py", line 992, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "virtualenv.py", line 960, in install_wheel
    'PIP_NO_INDEX': '1'
  File "virtualenv.py", line 902, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /tmp/virtualenv-1.11...rtualenv/bin/python2 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
@xen0n

This comment has been minimized.

Show comment
Hide comment
@xen0n

xen0n Mar 12, 2014

Contributor

This should be fixed in #516, but not merged to upstream yet. You can give that patched version a try~

Contributor

xen0n commented Mar 12, 2014

This should be fixed in #516, but not merged to upstream yet. You can give that patched version a try~

@biergaizi

This comment has been minimized.

Show comment
Hide comment
@biergaizi

biergaizi Mar 15, 2014

@xen0n Yes, it works fine :)

biergaizi commented Mar 15, 2014

@xen0n Yes, it works fine :)

@xen0n

This comment has been minimized.

Show comment
Hide comment
@xen0n

xen0n Mar 16, 2014

Contributor

The problem is actually virtualenv failing to respect the bitness of libdir, which is instead hard-coded to lib64; not finding bootstrap modules is just a consequence of not doing the symlink. My patch does just that required detection; is the approach acceptable (adding a file to site-packages/ indicating libdir bitness)? This is important for Python development on MIPS platforms such as various Loongson-based systems, and possibly x32 as well.

Contributor

xen0n commented Mar 16, 2014

The problem is actually virtualenv failing to respect the bitness of libdir, which is instead hard-coded to lib64; not finding bootstrap modules is just a consequence of not doing the symlink. My patch does just that required detection; is the approach acceptable (adding a file to site-packages/ indicating libdir bitness)? This is important for Python development on MIPS platforms such as various Loongson-based systems, and possibly x32 as well.

@umgeher

This comment has been minimized.

Show comment
Hide comment
@umgeher

umgeher Apr 20, 2014

I've the same problem, but I'm using pypy (freebsd 10).

@xen0n, I used your version, but I still got the same error.

Running virtualenv with interpreter /usr/local/bin/pypy
New pypy executable in tornapck/bin/pypy
Installing setuptools, pip...
  Complete output from command /usr/home/umgeher/wa...nv/tornapck/bin/pypy -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip:
  Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "app_main.py", line 578, in run_it
  File "<string>", line 1, in <module>
ZipImportError: No module named optparse
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "virtualenv.py", line 2373, in <module>
    main()
  File "virtualenv.py", line 820, in main
    symlink=options.symlink)
  File "virtualenv.py", line 988, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "virtualenv.py", line 956, in install_wheel
    'PIP_NO_INDEX': '1'
  File "virtualenv.py", line 898, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /usr/home/umgeher/wa...nv/tornapck/bin/pypy -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip failed with error code 1
/home/umgeher/war/git/virtualenv>

umgeher commented Apr 20, 2014

I've the same problem, but I'm using pypy (freebsd 10).

@xen0n, I used your version, but I still got the same error.

Running virtualenv with interpreter /usr/local/bin/pypy
New pypy executable in tornapck/bin/pypy
Installing setuptools, pip...
  Complete output from command /usr/home/umgeher/wa...nv/tornapck/bin/pypy -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip:
  Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "app_main.py", line 578, in run_it
  File "<string>", line 1, in <module>
ZipImportError: No module named optparse
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "virtualenv.py", line 2373, in <module>
    main()
  File "virtualenv.py", line 820, in main
    symlink=options.symlink)
  File "virtualenv.py", line 988, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "virtualenv.py", line 956, in install_wheel
    'PIP_NO_INDEX': '1'
  File "virtualenv.py", line 898, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /usr/home/umgeher/wa...nv/tornapck/bin/pypy -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip failed with error code 1
/home/umgeher/war/git/virtualenv>
@tingletech

This comment has been minimized.

Show comment
Hide comment
@tingletech

tingletech May 21, 2014

likewise, I can't get it work (I tried the version in the pull request)

bash-3.2$ python ./virtualenv-feature-explicit-libdir-bitness/virtualenv.py bootstrap_python
New python executable in bootstrap_python/bin/python
Installing setuptools, pip...
  Complete output from command /wowza/aws/bootstrap_python/bin/python -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/wowza/aws/virtualenv-feature-explicit-libdir-bitness/virtualenv_support/pip-1.5.dev1-py2.py3-none-any.whl/pip/__init__.py", line 3, in <module>
ImportError: No module named optparse
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 2373, in <module>
    main()
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 820, in main
    symlink=options.symlink)
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 988, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 956, in install_wheel
    'PIP_NO_INDEX': '1'
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 898, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /wowza/aws/bootstrap_python/bin/python -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip failed with error code 1
bash-3.2$ python -c "import optparse"
bash-3.2$ ./bootstrap_python/bin/python -c "import optparse"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named optparse
bash-3.2$ python --version
Python 2.6.7
bash-3.2$ ./bootstrap_python/bin/python --version       
Python 2.6.7

tingletech commented May 21, 2014

likewise, I can't get it work (I tried the version in the pull request)

bash-3.2$ python ./virtualenv-feature-explicit-libdir-bitness/virtualenv.py bootstrap_python
New python executable in bootstrap_python/bin/python
Installing setuptools, pip...
  Complete output from command /wowza/aws/bootstrap_python/bin/python -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/wowza/aws/virtualenv-feature-explicit-libdir-bitness/virtualenv_support/pip-1.5.dev1-py2.py3-none-any.whl/pip/__init__.py", line 3, in <module>
ImportError: No module named optparse
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 2373, in <module>
    main()
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 820, in main
    symlink=options.symlink)
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 988, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 956, in install_wheel
    'PIP_NO_INDEX': '1'
  File "./virtualenv-feature-explicit-libdir-bitness/virtualenv.py", line 898, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /wowza/aws/bootstrap_python/bin/python -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip failed with error code 1
bash-3.2$ python -c "import optparse"
bash-3.2$ ./bootstrap_python/bin/python -c "import optparse"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named optparse
bash-3.2$ python --version
Python 2.6.7
bash-3.2$ ./bootstrap_python/bin/python --version       
Python 2.6.7

@dstufft dstufft referenced this issue Jan 5, 2015

Closed

Rewrite virtualenv #697

0 of 5 tasks complete
@fuzzy76

This comment has been minimized.

Show comment
Hide comment
@fuzzy76

fuzzy76 Aug 18, 2016

I am seeing this on Debian... Anyone found a fix?

fuzzy76 commented Aug 18, 2016

I am seeing this on Debian... Anyone found a fix?

@tanin47

This comment has been minimized.

Show comment
Hide comment
@tanin47

tanin47 Mar 17, 2017

I encountered the same problem only when we use python -S (http://tanin.nanakorn.com/blogs/362). Using python without -S works fine. It might be related here.

tanin47 commented Mar 17, 2017

I encountered the same problem only when we use python -S (http://tanin.nanakorn.com/blogs/362). Using python without -S works fine. It might be related here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment