[英]ModuleNotFoundError: No module named 'python'
I have a python project and want to write a command line launcher.我有一个 python 项目,想写一个命令行启动器。 My project works fine when I run tests or launch from my IDE (pycharm).
当我从 IDE (pycharm) 运行测试或启动时,我的项目运行良好。 However when I try to launch via the command line I get a
ModuleNotFoundError: No module named 'python'
error.但是,当我尝试通过命令行启动时,我收到
ModuleNotFoundError: No module named 'python'
错误。
Here is my directory structure:这是我的目录结构:
.
├── Makefile
├── Pipfile
├── Pipfile.lock
├── README.md
├── create_jenkins_jobs.sh
└── python
├── __init__.py
├── create_credentials.py
├── create_jenkins_jobs_cli.py
├── credential_builder.py
├── jenkins_multibranch_job_builder.py
├── templates
│ ├── job.xml
│ ├── multibranch_job_template.xml
│ ├── ssh_cred_template.xml
│ └── user_pw_cred_template.xml
└── tests
├── __init__.py
├── integration
│ ├── __init__.py
│ ├── build_credential_test.py
│ ├── build_job_test.py
│ ├── conftest.py
│ ├── test_id_rsa
│ └── test_id_rsa.pub
└── unit
The shell script create_jenkins_jobs.sh
contains: shell 脚本
create_jenkins_jobs.sh
包含:
#!/bin/bash
python3 python/create_jenkins_jobs_cli.py "${@}"
the file create_jenkins_jobs_cli.py
contains the following code:文件
create_jenkins_jobs_cli.py
包含以下代码:
from typing import Set
from shared.common import preflight_env_check
from python.jenkins_multibranch_job_builder import JenkinsMultibranchJobBuilder
def configure_jenkins_jobs(git_repos: Set[str]):
jenkins_job_builder = JenkinsMultibranchJobBuilder(jenkins_server_url=JENKINS_BASE_SERVER_URL,
jenkins_folder=JENKINS_ROOT_JOB_FOLDER,
user=JENKINS_USER, token=JENKINS_TOKEN,
git_cred_id=GIT_SSH_CRED_ID,
git_repos=git_repos)
jenkins_job_builder.configure_jobs()
configure_jenkins_jobs(GIT_REPOS)
When I launch create_jenkins_jobs.sh
or create_jenkins_jobs_cli.py
I always get当我启动
create_jenkins_jobs.sh
或create_jenkins_jobs_cli.py
我总是得到
ModuleNotFoundError: No module named 'python'
$>./create_jenkins_jobs.sh
/Users/pswenson/dev/cc-cicd-automation/.venv/bin/python3: Error while finding module specification for 'python/create_jenkins_jobs_cli.py' (ModuleNotFoundError: No module named 'python/create_jenkins_jobs_cli')
I've tried all sorts of different techniques to get this to work with PYTHONPATH, working directories, etc...我已经尝试了各种不同的技术来让它与 PYTHONPATH、工作目录等一起工作......
It seems there is something basic about how python modules work that I don't understand.我不明白 python 模块如何工作的一些基本知识。
Does changing the line:是否更改线路:
from python.jenkins_multibranch_job_builder import JenkinsMultibranchJobBuilder
to至
from jenkins_multibranch_job_builder import JenkinsMultibranchJobBuilder
Sort you?给你排序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.