Skip to content

Support for Python 3 #1337

Closed
Closed

Description

@cclauss

See #1150, #1335, #1336, and https://travis-ci.com/nodejs/node/builds/79706150 (nodejs/node#21942)

  • Node Version:
  • Platform:
  • Compiler:
  • Module:
Verbose output (from npm or node-gyp):

Activity

  1. richardlau commented on Nov 14, 2017

    @richardlau
    Member

    Historically the blocker to this has been the gyp dependency and normally changes should be upstreamed there unless we're planning on forking gyp in which case we would want our own gyp project so that we can share the changes with the main Node.js project.

    cc @nodejs/gyp

  2. mthacker801 commented on Feb 8, 2018

    @mthacker801

    I cannot successfully install Angular on my mac. I keep getting gyp error and when I look at gyp-mac-tool it says:
    gyp verb command configure []
    gyp verb check python checking for Python executable "python2" in the PATH
    gyp verb which failed Error: not found: python2
    gyp verb which failed at getNotFoundError (/Users/thackerfam/AngularProj/angular-cli/node_modules/which/which.js:13:12)

    I have had python 3 installed forever and do not want python 2 as it can cause havoc to have both installed as they are not compatible with one another. If this is the reason for my inability to use Angular, what should I do?

  3. cclauss commented on Feb 8, 2018

    @cclauss
    ContributorAuthor

    On your Mac, what happens when you do:

    • python2 --version
    • /usr/bin/python --version
    • /usr/bin/python2 --version
    • /usr/bin/python2.7 --version

    I would highly recommend Homebrew as essential if you are doing real development on a Mac.

    Brew allows you to easily install both Python 2 and Python3 with: brew install python python@2

  4. cclauss commented on Feb 8, 2018

    @cclauss
    ContributorAuthor

    A few Python 2 issues on gyp:

    $ python2 -m flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

    ./gyptest.py:61:47: F821 undefined name 'opts'
        extra_path = [os.path.abspath(p) for p in opts.path]  # <-- 'opts' should be changed to 'args'
                                                  ^
    ./pylib/gyp/generator/make.py:1637:50: F821 undefined name 'target'
          print "WARNING: no output for", self.type, target  # <-- 'target' should be changes to 'self.target'
                                                     ^
    
  5. SatishMHiremath commented on Feb 17, 2018

    @SatishMHiremath

    I have faced and fixed this issue relates node-sass and python error.Try installing latest angular cli command with the steps below

    Set the system variable path as well:
    C:\Users\windowsusername\AppData\Roaming\npm

    C:\Users\windowsusername\AppData\Roaming\npm\node_modules@angular\cli\bin;

    C:\Program Files\nodejs;

    Then start using angular cli command prompt using:
    angular client project folder path>npm install -g @latest

    angular client project folder path>npm install -g node-gyp

  6. stanleyxu2005 commented on Feb 26, 2018

    @stanleyxu2005

    It's a bit embraced that the original gyp project relies on python 2, and after couple of years, the patch is getting too big so that no people is dare to review and merge it. Need to give the gyp community more feedback to move this forward.

  7. AdamMajer commented on Mar 2, 2018

    @AdamMajer

    Is there any interest in this? Python 2 is starting to get removed from distributions at this point.

  8. timoxley commented on Mar 3, 2018

    @timoxley

    Python 2 is starting to get removed from distributions at this point.

    Correct e.g. brew is now installing/upgrading to Python 3 by default.

    The following just worked for me as I already had a python2.7 executable installed via brew:

    npm config set python python2.7
    

    However, if you don't have a python2.7 executable, I suspect you can do something like:

    brew install python@2
    # follow the instructions printed after installing `python@2` to get python 2 on your PATH 
    # e.g. echo 'export PATH="/usr/local/opt/python@2/bin:$PATH"' >> ~/.bashrc
    npm config set python python2.7
  9. NetOpWibby commented on Mar 24, 2018

    @NetOpWibby

    Tim's method should go in the README. I use ZSH and there was a message mentioned Xcode when I installed Python 2 so my process was as follows:

    xcode-select --install
    
    brew install python@2
    echo 'export PATH="/usr/local/opt/python@2/bin:$PATH"' >> ~/.zshrc
    npm config set python python2.7
  10. ioquatix commented on May 4, 2018

    @ioquatix

    For some reason, npm config set python python2.7 stopped working for me. Even after setting it, I get the error that node-gyp is trying to run python 3.6

  11. cclauss commented on May 4, 2018

    @cclauss
    ContributorAuthor

    What does python2.7 --version return on your machine?

  12. ioquatix commented on May 4, 2018

    @ioquatix
    > python2.7 --version
    Python 2.7.14
    
  13. ioquatix commented on May 4, 2018

    @ioquatix

    Here is the full error

    ^_^ > apm install      
    Installing modules ✗
    > node-pty@0.7.4 install /Users/samuel/.atom/packages/script-runner/node_modules/node-pty
    > node scripts/install.js
    
    script-runner@3.0.0 /Users/samuel/.atom/packages/script-runner
    ├── etch@0.14.0 
    ├── resize-observer-polyfill@1.5.0 
    ├─┬ shell-environment@0.3.1 
    │ └─┬ os-locale@2.1.0 
    │   ├─┬ execa@0.7.0 
    │   │ ├─┬ cross-spawn@5.1.0 
    │   │ │ ├─┬ lru-cache@4.1.2 
    │   │ │ │ ├── pseudomap@1.0.2 
    │   │ │ │ └── yallist@2.1.2 
    │   │ │ ├─┬ shebang-command@1.2.0 
    │   │ │ │ └── shebang-regex@1.0.0 
    │   │ │ └─┬ which@1.3.0 
    │   │ │   └── isexe@2.0.0 
    │   │ ├── get-stream@3.0.0 
    │   │ ├─┬ npm-run-path@2.0.2 
    │   │ │ └── path-key@2.0.1 
    │   │ ├── p-finally@1.0.0 
    │   │ ├── signal-exit@3.0.2 
    │   │ └── strip-eof@1.0.0 
    │   ├─┬ lcid@1.0.0 
    │   │ └── invert-kv@1.0.0 
    │   └─┬ mem@1.1.0 
    │     └── mimic-fn@1.2.0 
    ├── shellwords@0.1.1 
    ├─┬ temp-write@3.4.0 
    │ ├── graceful-fs@4.1.11 
    │ ├── is-stream@1.1.0 
    │ ├── make-dir@1.2.0 
    │ ├── pify@3.0.0 
    │ ├── temp-dir@1.0.0 
    │ └── uuid@3.2.1 
    └── xterm@3.3.0 
    
    
    gyp ERR! configure error 
    gyp ERR! stack Error: Python executable "/Applications/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh" is v3.6.4, which is not supported by gyp.
    gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
    gyp ERR! stack     at failPythonVersion (/Applications/Atom.app/Contents/Resources/app/apm/node_modules/node-gyp/lib/configure.js:454:14)
    gyp ERR! stack     at /Applications/Atom.app/Contents/Resources/app/apm/node_modules/node-gyp/lib/configure.js:443:9
    gyp ERR! stack     at ChildProcess.exithandler (child_process.js:197:7)
    gyp ERR! stack     at emitTwo (events.js:106:13)
    gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
    gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
    gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:334:11)
    gyp ERR! stack     at emitOne (events.js:96:13)
    gyp ERR! stack     at Socket.emit (events.js:188:7)
    gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:498:12)
    gyp ERR! System Darwin 17.5.0
    gyp ERR! command "/Applications/Atom.app/Contents/Resources/app/apm/bin/node" "/Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/node-gyp" "rebuild"
    gyp ERR! cwd /Users/samuel/.atom/packages/script-runner/node_modules/node-pty
    gyp ERR! node -v v6.9.5
    gyp ERR! node-gyp -v v3.4.0
    gyp ERR! not ok 
    npm ERR! Darwin 17.5.0
    npm ERR! argv "/Applications/Atom.app/Contents/Resources/app/apm/bin/node" "/Applications/Atom.app/Contents/Resources/app/apm/node_modules/npm/bin/npm-cli.js" "--globalconfig" "/Users/samuel/.atom/.apm/.apmrc" "--userconfig" "/Users/samuel/.atom/.apmrc" "install" "--runtime=electron" "--target=1.7.11" "--arch=x64"
    npm ERR! node v6.9.5
    npm ERR! npm  v3.10.10
    npm ERR! code ELIFECYCLE
    
    npm ERR! node-pty@0.7.4 install: `node scripts/install.js`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the node-pty@0.7.4 install script 'node scripts/install.js'.
    npm ERR! Make sure you have the latest version of node.js and npm installed.
    npm ERR! If you do, this is most likely a problem with the node-pty package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR!     node scripts/install.js
    npm ERR! You can get information on how to open an issue for this project with:
    npm ERR!     npm bugs node-pty
    npm ERR! Or if that isn't available, you can get their info via:
    npm ERR!     npm owner ls node-pty
    npm ERR! There is likely additional logging output above.
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     /Users/samuel/.atom/packages/script-runner/npm-debug.log
    

    Here is my config

     > apm config list
    ; cli configs
    globalconfig = "/Users/samuel/.atom/.apm/.apmrc"
    user-agent = "npm/3.10.10 node/v6.9.5 darwin x64"
    userconfig = "/Users/samuel/.atom/.apmrc"
    
    ; environment configs
    node-gyp = "/Applications/Atom.app/Contents/Resources/app/apm/bin/../node_modules/.bin/node-gyp"
    python = "/Applications/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh"
    
    ; userconfig /Users/samuel/.atom/.apmrc
    
    ; globalconfig /Users/samuel/.atom/.apm/.apmrc
    cache = "/Users/samuel/.atom/.apm"
    progress = false
    
    ; node bin location = /Applications/Atom.app/Contents/Resources/app/apm/bin/node
    ; cwd = /Users/samuel/.atom/packages/script-runner
    ; HOME = /Users/samuel/.atom/.node-gyp
    ; "npm config ls -l" to show all defaults.
    
    ^_^ > npm config list
    ; cli configs
    user-agent = "npm/3.10.10 node/v8.10.0 darwin x64"
    
    ; userconfig /Users/samuel/.npmrc
    init.author.email = "samuel.williams@oriontransfer.co.nz"
    init.author.name = "Samuel Williams"
    init.author.url = "http://www.codeotaku.com"
    python = "python2.7"
    
    ; node bin location = /opt/local/bin/node
    ; cwd = /Users/samuel/.atom/packages/script-runner
    ; HOME = /Users/samuel
    ; "npm config ls -l" to show all defaults.
    

    Hmm, I'm sure I also had apm config set python=python2.7. Maybe that's why it's not working.

  14. ioquatix commented on May 4, 2018

    @ioquatix

    That's odd, maybe it's a bug in apm.

    > apm config set python python2.7
    > apm config list                
    ; cli configs
    globalconfig = "/Users/samuel/.atom/.apm/.apmrc"
    user-agent = "npm/3.10.10 node/v6.9.5 darwin x64"
    userconfig = "/Users/samuel/.atom/.apmrc"
    
    ; environment configs
    node-gyp = "/Applications/Atom.app/Contents/Resources/app/apm/bin/../node_modules/.bin/node-gyp"
    python = "/Applications/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh"
    
    ; userconfig /Users/samuel/.atom/.apmrc
    
    ; globalconfig /Users/samuel/.atom/.apm/.apmrc
    cache = "/Users/samuel/.atom/.apm"
    progress = false
    
    ; node bin location = /Applications/Atom.app/Contents/Resources/app/apm/bin/node
    ; cwd = /Users/samuel/.atom/packages/script-runner
    ; HOME = /Users/samuel/.atom/.node-gyp
    ; "npm config ls -l" to show all defaults.
    

    Even thought I set it, it's not changed in the config!?

  15. raininja commented on May 7, 2018

    @raininja

    @ioquatix what does "apm config get" show?

    [raijin@ishtar][~]%apm config get
    ; cli configs
    globalconfig = "/home/raijin/.atom/.apm/.apmrc"
    user-agent = "npm/3.10.10 node/v6.9.5 linux x64"
    userconfig = "/home/raijin/.atom/.apmrc"
    
    ; environment configs
    node-gyp = "/usr/share/atom/resources/app/apm/bin/../node_modules/.bin/node-gyp"
    
    ; userconfig /home/raijin/.atom/.apmrc
    python = "python2.7"
    
    ; globalconfig /home/raijin/.atom/.apm/.apmrc
    cache = "/home/raijin/.atom/.apm"
    progress = false
    
    ; node bin location = /usr/share/atom/resources/app/apm/bin/node
    ; cwd = /home/raijin
    ; HOME = /home/raijin/.atom/.node-gyp
    ; "npm config ls -l" to show all defaults.
    
  16. 53 remaining items

  17. cclauss commented on Jun 5, 2019

    @cclauss
    ContributorAuthor

    @mingrammer #1723 (comment) lists some current Python 3 incompatibilities if you have some time to work on this. We also created GYP3 nodejs/node#26620

  18. MattIPv4 commented on Jul 6, 2019

    @MattIPv4
    Member

    Would it be possible to edit the opening post in this thread with a general summary of the situation with regards to the move to Python 3 due to the Python 2 EOL and drop from Brew/macOS/Linux distros? It'd be great if that could then be kept up to date so the average user can easily see an overview of the current situation and the plan going forward :)

  19. cclauss commented on Jul 7, 2019

    @cclauss
    ContributorAuthor

    Closing this PR as GYP seems to be Python 3 compatible:

    If you find any Python 3 incompatibles in this code, please open an issue.

    NOTE: nodejs/node is not yet compatible with Python 3 but an effort is ongoing there.

  20. superern commented on Aug 3, 2019

    @superern

    Python 2 is starting to get removed from distributions at this point.

    Correct e.g. brew is now installing/upgrading to Python 3 by default.

    The following just worked for me as I already had a python2.7 executable installed via brew:

    npm config set python python2.7
    

    However, if you don't have a python2.7 executable, I suspect you can do something like:

    brew install python@2
    # follow the instructions printed after installing `python@2` to get python 2 on your PATH 
    # e.g. echo 'export PATH="/usr/local/opt/python@2/bin:$PATH"' >> ~/.bashrc
    npm config set python python2.7

    Thanks! this resolves my issues

  21. assigned and unassigned on Mar 8, 2020
  22. slim-hmidi commented on Jul 1, 2020

    @slim-hmidi

    I'm using Node.js v 12.18.2 and Python v3.8.1 on windows 10 and when I tried to run npm install I got this error:

    gyp ERR! configure error
    gyp ERR! stack Error: Command failed: C:\Program Files (x86)\Python\Python\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
    gyp ERR! stack   File "<string>", line 1
    gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
    gyp ERR! stack                       ^
    gyp ERR! stack SyntaxError: invalid syntax
    gyp ERR! stack
    gyp ERR! stack     at ChildProcess.exithandler (child_process.js:303:12)
    gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
    gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
    gyp ERR! System Windows_NT 10.0.17134
    gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\x199377\\AppData\\Local\\Programs\\Git\\react-whiteapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
    gyp ERR! cwd C:\Users\x199377\AppData\Local\Programs\Git\react-whiteapp\node_modules\node-sass
    gyp ERR! node -v v12.18.2
    gyp ERR! node-gyp -v v3.8.0
    gyp ERR! not ok
    Build failed with error code: 1
    
  23. cclauss commented on Jul 1, 2020

    @cclauss
    ContributorAuthor

    gyp ERR! node-gyp -v v3.8.0

    Please upgrade node-gyp to v7 https://github.com/nodejs/node-gyp/releases

  24. richardlau commented on Jul 1, 2020

    @richardlau
    Member

    @slim-hmidi If you want to use Python 3 you'll have to take up with node-sass as they're still depending on node-gyp ^3.8.0: https://github.com/sass/node-sass/blob/e1fc1580c2e979113c95850b8ae5d83845063ca5/package.json#L67

    node-gyp added Python 3 support in the 5.x and later releases.

  25. slim-hmidi commented on Jul 1, 2020

    @slim-hmidi

    @richardlau I installed python v2.7.16 but still the same problem.

  26. richardlau commented on Jul 1, 2020

    @richardlau
    Member

    If you have the same problem it means that node-gyp is still trying to use Python 3. Maybe try setting the PYTHON environment variable to point to your installed Python 2?

  27. slim-hmidi commented on Jul 1, 2020

    @slim-hmidi

    I uninstalled python 3 and python 2.7.16 and I'm reinstalling python 2.7.16 again and I will try again.

  28. slim-hmidi commented on Jul 1, 2020

    @slim-hmidi

    @richardlau it works now. thanks

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions