Ubuntu: Can't setup virtualenv for python
Question: I'm using Ubuntu. I tried to follow the [Deploying a Django on Amazon Elastic
Beanstalk](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html).

Rather than using `yum`, i used `apt-get` instead.

I followed every ahead steps well.

    
    
    root@james-MacBookPro:/home/james# virtualenv --version
    1.7.2
    root@james-MacBookPro:/home/james# python --version
    Python 2.7.6
    root@james-MacBookPro:/home/james# apt-get install  python-dev
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    python-dev is already the newest version.
    0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
    root@james-MacBookPro:/home/james# apt-get install python2.7-dev
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    python2.7-dev is already the newest version.
    0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
    

But when i tried to create a virtual environment for django development, some
things wrong. I typed `virtualenv -p python2.6 /tmp/djangodev`

    
    
    root@james-MacBookPro:/home/james# virtualenv -p python2.7 /tmp/djangodev
    Running virtualenv with interpreter /usr/bin/python2.7
    New python executable in /tmp/djangodev/bin/python2.7
    Not overwriting existing python script /tmp/djangodev/bin/python (you must use /tmp/djangodev/bin/python2.7)
    Installing setuptools...................................
      Complete output from command /tmp/djangodev/bin/python2.7 -c "#!python
    \"\"\"Bootstra...sys.argv[1:])
    
    
    " /usr/local/lib/pytho...ols-0.6c11-py2.7.egg:
      Traceback (most recent call last):
          File "<string>", line 279, in <module>
          File "<string>", line 240, in main
          File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1712, in main
          File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
      File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1716, in <lambda>
      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python2.7/distutils/dist.py", line 971, in run_command
        cmd_obj.ensure_finalized()
      File "/usr/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
        self.finalize_options()
      File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 125, in finalize_options
      File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1121, in _expand
      File "/usr/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command
        cmd_obj.ensure_finalized()
      File "/usr/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
        self.finalize_options()
      File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg/setuptools/command/install.py", line 32, in finalize_options
      File "/usr/lib/python2.7/distutils/command/install.py", line 321, in finalize_options
        (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
      File "/tmp/djangodev/lib/python2.7/distutils/__init__.py", line 85, in sysconfig_get_config_vars
        real_vars = old_get_config_vars(*args)
      File "/usr/lib/python2.7/distutils/sysconfig.py", line 495, in get_config_vars
    func()
      File "/usr/lib/python2.7/distutils/sysconfig.py", line 439, in _init_posix
        from _sysconfigdata import build_time_vars
      File "/usr/lib/python2.7/_sysconfigdata.py", line 6, in <module>
        from _sysconfigdata_nd import *
    ImportError: No module named _sysconfigdata_nd
    ----------------------------------------
    ...Installing setuptools...done.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2429, in <module>
        main()
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 942, in main
        never_download=options.never_download)
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1052, create_environment
        search_dirs=search_dirs, never_download=never_download)
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 598, in install_setuptools
        search_dirs=search_dirs, never_download=never_download)
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 570, in _install_req
    cwd=cwd)
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1020, in call_subprocess
        % (cmd_desc, proc.returncode))
    OSError: Command /tmp/djangodev/bin/python2.7 -c "#!python
    \"\"\"Bootstra...sys.argv[1:])
    
    
    
    " /usr/local/lib/pytho...ols-0.6c11-py2.7.egg failed with error code 1
    

Can someone tell me what's wrong and how to fix it?


Answer: This is caused by a known
[bug](https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/1115466) in
Ubuntu.

Fix this creating a softlink of module `_sysconfigdata_nd.py` in `python2.7`
dir:

    
    
    cd /usr/lib/python2.7
    sudo ln -s plat-x86_64-linux-gnu/_sysconfigdata_nd.py .
    

(or use

    
    
    sudo ln -s plat-i386-linux-gnu/_sysconfigdata_nd.py .
    

if you are on an i386 system)

