Skip to content
New issue

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

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

Already on GitHub? # to your account

Python 3 support #58

Merged
merged 2 commits into from
Apr 3, 2014
Merged

Python 3 support #58

merged 2 commits into from
Apr 3, 2014

Conversation

apragacz
Copy link
Contributor

@apragacz apragacz commented Apr 2, 2014

This pull request fixes #42 (support for python 3.*) . The solution relies on the fact that there is a python2 executable, and it can be found via the "which python2" command.

  • Temporarily pointing the python executable to the python2 for ./configure, make, make install. The Node.js build scripts are currently using python 2.*. We should start to advocate for python3 support there, but this may take some time.
  • Fixed some inconsistences causing the writefile() function to fail in python 3.*

This solution was tested with success on Ubuntu Linux 13.10, with python 2.7.5 and 3.3.2 preinstalled.

  • on python 3 virtualenv created by pyenv-3.3 command and patched with following commands:

    wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
    wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py -O - | python
    

    (setuptools & pip are included from the 3.4 version AFAIK)

  • on python 2 virtualenv created by virtualenv command

ekalinin added a commit that referenced this pull request Apr 3, 2014
@ekalinin ekalinin merged commit 2e66f71 into ekalinin:master Apr 3, 2014
@erichaus
Copy link

erichaus commented Nov 3, 2014

hello, I am trying to get nodeenv installed in a virtualenv with python3.4, I get the following error:

$ nodeenv node

  • Install node.js (0.10.33) .Traceback (most recent call last):
    File "/Users/eric/.virtualenvs/clandestine/src/nodeenv/nodeenv.py", line 506, in build_node_from_src
    ['which', 'python2'], opt.verbose, True, node_src_dir, env
    File "/Users/eric/.virtualenvs/clandestine/src/nodeenv/nodeenv.py", line 420, in callit
    % (cmd_desc, proc.returncode))
    OSError: Command which python2 failed with error code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/eric/.virtualenvs/clandestine/bin/nodeenv", line 9, in
load_entry_point('nodeenv==0.11.1', 'console_scripts', 'nodeenv')()
File "/Users/eric/.virtualenvs/clandestine/src/nodeenv/nodeenv.py", line 765, in main
create_environment(env_dir, opt)
File "/Users/eric/.virtualenvs/clandestine/src/nodeenv/nodeenv.py", line 674, in create_environment
install_node(env_dir, src_dir, opt)
File "/Users/eric/.virtualenvs/clandestine/src/nodeenv/nodeenv.py", line 563, in install_node
build_node_from_src(env_dir, src_dir, node_src_dir, opt)
File "/Users/eric/.virtualenvs/clandestine/src/nodeenv/nodeenv.py", line 511, in build_node_from_src
'Python >=3.0 virtualenv detected, but no python2 '
OSError: Python >=3.0 virtualenv detected, but no python2 command (required for building node.js) was found

What should I do?

@ekalinin
Copy link
Owner

ekalinin commented Nov 3, 2014

What should I do?

You need to install python2. As Node's building system supports only python 2.6 or 2.7

Or try to install node.js from prebuilt package:

$ nodeenv --prebuilt node

@erichaus
Copy link

erichaus commented Nov 3, 2014

hey @ekalinin, thanks for reply! when I ran above code I get "* Environment already exists: node". Is that referring to my global npm install? Should I remove that? Im trying to determine a best practice for managing node packages/code in conjunction with my django/other projects...

thanks!

@ekalinin
Copy link
Owner

ekalinin commented Nov 5, 2014

hey @erichonkanen

when I ran above code I get "* Environment already exists: node". Is that referring to my global npm install?

Nope, it's about virtualenv's folder. It already exists (node folder in your example).

Should I remove that?

Seems, it better to use --force option.
But you can use rm node as well.

Im trying to determine a best practice for managing node packages/code in conjunction with my django/other projects...

If you're using virtualenv (for django) then it's better to use the same environment for python & node.js:

# some environment for python/django
$ virtualenv env
$ . env/bin/activate
# install nodeenv into python's virtualenv
(env) $ pip install nodeenv
# add nodejs in the same virtualenv
(env) $ nodeenv -p --prebuilt

@kodonnell
Copy link

Hi @ekalinin

I wasn't even aware of the lack of python3 support for node until I came across my own error, and hence this issue -- for me, everything has worked fine with python3.4 and pyvenv-3.4. That is, until I tried to update from a requirements file:

$ freeze -l requirements_node.txt 
$ cat requirements_node.txt 
1:2:canvas@1.1.6
2:3:d3@3.5.3
3:4:vega@1.4.3

All fine so far. However:

nodeenv --requirements=requirements_node.txt --update env
* Install node.js packages ... Traceback (most recent call last):
File "/home/kane/dml/kane_test/env/bin/nodeenv", line 9, in <module>
load_entry_point('nodeenv==0.11.1', 'console_scripts', 'nodeenv')()
File "/home/kane/dml/kane_test/env/lib/python3.4/site-packages/nodeenv.py", line 762, in main
install_packages(env_dir, opt)
File "/home/kane/dml/kane_test/env/lib/python3.4/site-packages/nodeenv.py", line 608, in install_packages
cmd % {"pack": package}], show_stdout=opt.verbose, in_shell=True)
File "/home/kane/dml/kane_test/env/lib/python3.4/site-packages/nodeenv.py", line 420, in callit
% (cmd_desc, proc.returncode))
OSError: Command ". env/bin/activate &... -g 1:2:canvas@1.1.6" failed with error code 1

I've had a look at the source code, and it would appear that the install_packages function is causing the issue. The violating command is cmd = '. ' + pipes.quote(activate_path) + ' && npm install -g %(pack)s', and I believe I'm getting an error as I've been doing my installs with npm --python=python2.7 .... Am I interpreting this correctly? If so, would there be any reason not to add this option, i.e. cmd = '. ' + pipes.quote(activate_path) + ' && npm --python=python2 install -g %(pack)s' ?

Update: I figured out npm config set python python2.7, and now I can install without the --python=python2.7 option, but I'm afraid it doesn't fix the issue with updating of requirements. Odd, I thought I had it there.

Thanks for your time.

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

Successfully merging this pull request may close these issues.

nodenv -p fails while using python3.3
4 participants