cdk8s-team / cdk8s

Define Kubernetes native apps and abstractions using object-oriented programming
https://cdk8s.io
Apache License 2.0
4.29k stars 290 forks source link

[BUG] Unable to run Python version of cdk8s #170

Closed ratnadeep007 closed 4 years ago

ratnadeep007 commented 4 years ago

Describe the bug Created new cdk8s python project and ran cdk8s synth got following error.

Error: the command ./main.py could not be found within PATH or Pipfile's [scripts].
Error: non-zero exit code 1
    at ChildProcess.<anonymous> (/usr/local/Cellar/cdk8s/0.21.0/libexec/lib/node_modules/cdk8s-cli/lib/util.js:18:27)
    at Object.onceWrapper (events.js:418:26)
    at ChildProcess.emit (events.js:311:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)

Also tried running hello-python example getting following error:

Traceback (most recent call last):
  File "./main.py", line 2, in <module>
    from constructs import Construct
ModuleNotFoundError: No module named 'constructs'
Error: non-zero exit code 1
    at ChildProcess.<anonymous> (/usr/local/Cellar/cdk8s/0.21.0/libexec/lib/node_modules/cdk8s-cli/lib/util.js:18:27)
    at Object.onceWrapper (events.js:418:26)
    at ChildProcess.emit (events.js:311:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)

To Reproduce

  1. Initialized app using cdk8s init python-app
  2. pipenv install followed by cdk8s import --language python then ran cdk8s synth

For hello-python followed instructions from README which is same as step 2

Expected behavior To get manifest files in dist folder

Additional context Operating System: macOS Mojave Python version: 3.8 and 3.7 Pipenv version: 2018.11.26 cdk8s Installation method: Homebrew Shell: Tried with Bash, Zsh, Fish

030 commented 4 years ago

The app was installed using pip see, https://pypi.org/project/cdk8s/0.21.0/, but when cdk8s is run, the command cannot be found.

eladb commented 4 years ago

Not reproducing in 0.23.0. Closing for now. Please reopen if this persists.

030 commented 4 years ago

@eladb Sorry, but it does not seem to work. I just installed 0.24.0 and when I issue cdk8s, a command not found is returned. If I run the sample code, it does not work as well:

from constructs import Construct, Node

from imports import k8s

python file.py, returns:

Traceback (most recent call last):
  File "file.py", line 4, in <module>
    from imports import k8s
ModuleNotFoundError: No module named 'imports'
eladb commented 4 years ago

Do you have an imports directory in your project? (did you run cdk8s import?). Also, what python version are you using?

030 commented 4 years ago
pip3 list
Package                Version      
---------------------- -------------  
cdk8s                  0.24.0
python3 --version
Python 3.8.2

Although cdk8s has been installed according to pip, the executable cannot be found on the path, while this works for other python executables.

trevorrobertsjr commented 4 years ago

Additional context Operating System: macOS Mojave Python version:3.7 Pipenv version: version 2020.6.2 cdk8s Installation method: Homebrew (0.24.0) Shell: Bash

I'm getting the following error output when I try to do a cdk8s init:

`{ Error: Command failed: pipenv run ./main.py Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning. Warning: There was an unexpected error while activating your virtualenv. Continuing anyway... File "./main.py", line 7 def init(self, scope: Construct, ns: str): ^ SyntaxError: invalid syntax

at checkExecSyncError (child_process.js:629:11)
at execSync (child_process.js:666:13)
at Object.exports.post.options [as post] (/usr/local/Cellar/cdk8s/0.24.0/libexec/lib/node_modules/cdk8s-cli/templates/python-app/.hooks.sscaff.js:27:3)
at executePostHook (/usr/local/Cellar/cdk8s/0.24.0/libexec/lib/node_modules/cdk8s-cli/node_modules/sscaff/lib/sscaff.js:61:37)
at Object.sscaff (/usr/local/Cellar/cdk8s/0.24.0/libexec/lib/node_modules/cdk8s-cli/node_modules/sscaff/lib/sscaff.js:28:15)

status: 1, signal: null, output: [ null,

, ], pid: 85215, stdout: , stderr: }`
trevorrobertsjr commented 4 years ago

For anyone who may be running into this. I resolved due to a hint I picked up in the CDK documentation that pointed to cdk.json as an area that may need to be updated: https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-python.html

cdk8s doesn't have this config file, AFAIK, but I changed the Python interpreter command in in the cdk8s-generated main.py to python3 instead of python due to way that Python 3.7 is installed on my Mac.

Now my Mac is correctly-generating Python-based cdk8s manifests. I hope that helps someone else.