projen / projen

Rapidly build modern applications with advanced configuration management
https://projen.io
Apache License 2.0
2.59k stars 369 forks source link

new python project creation crashes on windows #1003

Closed Unerty closed 4 hours ago

Unerty commented 3 years ago

Can't create a python project. pip executable is not found by projen, despite it's installed and available.

Given:

When executing the following:

mkdir newpython
cd newpython
git init
npx projen new python

Then, the process ends with an error:

'pip' is not recognized as an internal or external command,
operable program or batch file.

Full log:

C:\Users\Ivan\PycharmProjects\newpython>git init
Initialized empty Git repository in C:/Users/Ivan/PycharmProjects/newpython/.git/

C:\Users\Ivan\PycharmProjects\newpython>node -v
v16.6.2

C:\Users\Ivan\PycharmProjects\newpython>npm -v
7.20.3

C:\Users\Ivan\PycharmProjects\newpython>npx -v
7.20.3

C:\Users\Ivan\PycharmProjects\newpython>python --version
Python 3.9.6

C:\Users\Ivan\PycharmProjects\newpython>pip --version
pip 21.1.3 from c:\python39\lib\site-packages\pip (python 3.9)

C:\Users\Ivan\PycharmProjects\newpython>npx projen new python
✨ Project definition file was created at C:\Users\Ivan\PycharmProjects\newpython\.projenrc.js
✨ Synthesizing project...
✨ Setting up a virtual environment...
🤖 python -m venv .env
✨ Environment successfully created (located in ./.env).
✨ Installing dependencies...
🤖 install | env: VIRTUAL_ENV=$PWD/.env PATH=$PWD/.env/bin:$PATH
🤖 install | pip install --upgrade pip
'pip' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\tasks\runtime.js:143
                    throw new Error(`Task "${this.fullname}" failed when executing "${command}" (cwd: ${path_1.resolve(cwd !== null && cwd !== void 0 ? cwd : this.workdir)})`);
                    ^

Error: Task "install" failed when executing "pip install --upgrade pip" (cwd: C:\Users\Ivan\PycharmProjects\newpython)
    at new RunTask (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\tasks\runtime.js:143:27)
    at TaskRuntime.runTask (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\tasks\runtime.js:62:9)
    at Pip.installDependencies (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\python\pip.js:56:17)
    at PythonProject.postSynthesize (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\python\python-project.js:152:26)
    at PythonProject.synth (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\project.js:293:18)
    at evalmachine.<anonymous>:19:9
    at Script.runInContext (node:vm:139:12)
    at Object.runInContext (node:vm:289:6)
    at createProject (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\cli\cmds\new.js:120:8)
    at newProject (C:\Users\Ivan\AppData\Roaming\npm\node_modules\projen\lib\cli\cmds\new.js:248:5)

C:\Users\Ivan\PycharmProjects\newpython>
eladb commented 3 years ago

Looks like a Windows-related issue

github-actions[bot] commented 2 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

github-actions[bot] commented 2 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

github-actions[bot] commented 2 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

github-actions[bot] commented 2 years ago

Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

DeadlySquad13 commented 1 year ago

Sorry but is this issue going to be fixed? Seems like a big disappointment for me as a new user discovering this cool project!

mrgrain commented 1 year ago

@DeadlySquad13 Thanks for pointing this out. I've reopened the issue. Contributions are welcome!

dineshSajwan commented 1 year ago

Hi , has there been any fix on this issue? It's seems like a deal breaker on windows. Looks like WSL is the only way to go about it?

aracg commented 7 months ago

Stumbled upon similar error when trying to run npx projen new awscdk-app-py --poetry on windows, thought it was poetry-related but it looks it's a wider issue.

lzmkhan commented 6 months ago

I guess this is still not fixed. :( I get the same error when creating python project

mrgrain commented 1 month ago

I guess this is still not fixed. :( I get the same error when creating python project

@lzmkhan can you run pip independently of projen? I'm wondering if this might be an environment setup issue (which would currently be out of scope for projen).

amit-cubit commented 1 month ago

I get this error when running the command ""npx projen new awscdk-app-py"" 👾 Project definition file was created at E:\test.projenrc.py 👾 Setting up a virtual environment... 👾 Environment successfully created (located in ./.env). 👾 Installing dependencies... 👾 install | pip install --upgrade pip 'pip' is not recognized as an internal or external command, operable program or batch file. C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\task-runtime.js:147 throw new Error(Task "${this.fullname}" failed when executing "${command}" (cwd: ${(0, path_1.resolve)(cwd ?? this.workdir)})); ^

Error: Task "install" failed when executing "pip install --upgrade pip" (cwd: E:\test) at new RunTask (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\task-runtime.js:147:27) at TaskRuntime.runTask (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\task-runtime.js:52:9) at Pip.installDependencies (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\python\pip.js:51:17) at AwsCdkPythonApp.postSynthesize (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\python\python-project.js:172:26) at AwsCdkPythonApp.synth (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\project.js:357:18) at evalmachine.:20:19 at Script.runInContext (node:vm:148:12) at Object.runInContext (node:vm:300:6) at createProject (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\projects.js:97:8) at Projects.createProject (C:\Users\NITRO 5\AppData\Local\npm-cache_npx\80cfb0dc84733c29\node_modules\projen\lib\projects.js:30:9)

BUt globally pip is fully installed in the latest version

mrgrain commented 1 month ago

Thanks @amit-cubit for reporting. What happens if you try running this command:

cmd.exe /c "pip --version"

This checks if cmd.exe can find pip. Which is what projen does under the hood. If the command doesn't print the pip version, something isn't working in your environment.

amit-cubit commented 1 month ago

the pip --version command works E:>cmd.exe /c "pip --version" pip 24.2 from C:\Users\NITRO 5\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)

mrgrain commented 1 month ago

Thanks for running the command @amit-cubit I'm still trying to reproduce this. Not entirely sure what the issue is yet. 😕

amit-cubit commented 1 month ago

The above issue appears to be about the python in the virtual env created by projen. There the pip version is 22 and upgrade command fails when executed with the .env activated.

Is there a workaround for this?

mrgrain commented 4 weeks ago

Hmm. You could try using the --pipenv or --poetry flag. Maybe they can deal better with Windows.

matt9ucci commented 3 weeks ago

'pip' is not recognized as an internal or external command,

The error might be due to the generated PATH in .projen/tasks.json like this:

"PATH": "$(echo $PWD/.env/bin:$PATH)"

The value is not valid for Windows:

A workaround is to add the following line to .projenrc.py:

project.tasks.add_environment('PATH', '$(echo %cd%\\.env\\Scripts;%PATH%)')

It will overwrite the PATH like this:

"PATH": "$(echo %cd%\\.env\\Scripts;%PATH%)"
harmjeff commented 3 weeks ago

Keeping this issue alive, Same issue on windows: 👾 Project definition file was created at C:\dev\test\projen-test.projenrc.py 👾 Setting up a virtual environment... 👾 Environment successfully created (located in ./.env). 👾 Installing dependencies... 👾 install | pip install --upgrade pip 'pip' is not recognized as an internal or external command, operable program or batch file. C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\task-runtime.js:147 throw new Error(Task "${this.fullname}" failed when executing "${command}" (cwd: ${(0, path_1.resolve)(cwd ?? this.workdir)})); ^

Error: Task "install" failed when executing "pip install --upgrade pip" (cwd: C:\dev\test\projen-test) at new RunTask (C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\task-runtime.js:147:27) at TaskRuntime.runTask (C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\task-runtime.js:52:9) at Pip.installDependencies (C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\python\pip.js:51:17) at PythonProject.postSynthesize (C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\python\python-project.js:172:26) at PythonProject.synth (C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\project.js:357:18) at evalmachine.:19:20 at Script.runInContext (node:vm:133:12) at Object.runInContext (node:vm:281:6) at createProject (C:\Users\harmjeff\AppData\Roaming\nvm\v18.20.4\node_modules\projen\lib\projects.js:97:8)

mrgrain commented 3 weeks ago

Great lead @matt9ucci