Skip to content
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

manage.py: detect virtualenv2 for environments with py2 & py3 #39

Open
nphyx opened this issue Jun 22, 2014 · 7 comments
Open

manage.py: detect virtualenv2 for environments with py2 & py3 #39

nphyx opened this issue Jun 22, 2014 · 7 comments

Comments

@nphyx
Copy link

nphyx commented Jun 22, 2014

In at least some linux environments (e.g. Arch Linux), python 2.x and python 3.x run side by side, with the python 2 binary and tools suffixed with "2" (python2, virtualenv2, etc). Consider updating manage.py to detect virtualenv version number, and look for virtualenv2 executable if virtualenv is not found or is from python 3.x.

I made a simple change from "virtualenv" to "virtualenv2" to fix this in the meanwhile but it'll break every other environment so I won't do a pull request. I'm not experienced enough in python to do it the "smart" way described above.

@nphyx
Copy link
Author

nphyx commented Jun 22, 2014

Note: looks like several of the install scripts need to run "python2" binary as well.

@neuromancer85
Copy link

As a workaround, this is what I did on Arch Linux (but should be the same on any distro):

  • install python2-virtualenv
  • create a virtualenv: $ virtualenv2 venv
  • activate it: $ source venv/bin/activate
  • install virtualenv in the virtualenv: $ pip install virtualenv
  • from inside the virtualenv, run the $ python manage.py env script
  • wait for it to finish, deactivate the virtualenv: $ deactivate
  • you're done!

@nphyx
Copy link
Author

nphyx commented Jul 8, 2014

Thanks!

@bmaltby
Copy link
Member

bmaltby commented Jul 9, 2014

Can you try changing line 36 of manage.py from
cmd = 'virtualenv -p %s --no-site-packages %s' % (PYTHON, env_dir)
to
cmd = '%s -m virtualenv -p %s --no-site-packages %s' % (sys.executable, PYTHON, env_dir)
and see if that would fix your issues.

@nphyx
Copy link
Author

nphyx commented Jul 9, 2014

Not quite.

cmd = '%s -m /usr/bin/virtualenv2 -p %s --no-site-packages %s' % (sys.executable, PYTHON, env_dir)

Will get me part of the way there, but it fails during nodejs install:

Executing: ./configure --prefix=/home/nphyx/src/turbulenz_engine/env
  File "./configure", line 224
    '''
      ^
SyntaxError: invalid syntax
Error building nodejs from source.

Is there any way to skip the nodejs install? I already have it installed anyway and this is consistently where it fails.

@bmaltby
Copy link
Member

bmaltby commented Jul 10, 2014

Can you try also editing the block of code around line 80 of manage.py to look like this

cmd = [os.path.join(env_bin, 'python'),
       os.path.join(TURBULENZROOT, 'scripts', 'install_nodejs.py'),
       '--prefix', env_dir,
       '--typescript']
new_env = os.environ.copy()
new_env['PATH'] = '%s:%s' % (env_bin, os.environ['PATH'])
if not TURBULENZOS in ['linux32', 'linux64']:
    cmd.append('-f')
sh(cmd, env=new_env, console=True)

Note it's adding the two lines setting up new_env and then passing that to the sh cmd on the last line. This is needed because the nodejs build process expects the default python (i.e. first one on the path to be python 2.6 or 2.7) and it appears under your arch linux install it's python 3. Because we build an isolated environment with virtualenv we just need to get that into the front of the path before calling the nodejs build process to ensure we use the python from there.
While we could skip nodejs installation there are times that we may require a specific version and we don't like to force people to upgrade their system (potentially breaking other things they're working on) to use Turbulenz. Hence we feel it's safer to always provide as much of an isolated Turbulenz environment as we can.

@nphyx
Copy link
Author

nphyx commented Oct 30, 2014

Hey, sorry it took me so long to get back to you. Other more pressing projects have taken up my time the last few months. I did eventually get this to work with the following (and your patch above):

Instead of:

python manage.py env

Used:

virtualenv2 -p python2.7 --no-site-packages ./env
source env/bin/activate

Inside the env:

python manage.py env
python manage.py jslib
python manage.py tools

Etc. following the startup guide. I guess we can consider this issue closed, though it might be nice to leave a note for future Arch Linux users. A simple alternative might be just to run a barebones Ubuntu LTS release in a virtual machine.

Edit: nevermind this wasn't a complete solution. I'll get back with further comments tomorrow.

Edit edit: notes above updated. Looks like it's all good now, yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants