简体   繁体   English

Gitlab-ci 无法识别 python

[英]Gitlab-ci does not recognize python

I want to run my Jupyter notebooks with my pipeline.我想用我的管道运行我的 Jupyter 笔记本。 To do this i need runipy .为此,我需要runipy And to install runipy on the gitlab runner i need python.并且要在 gitlab 跑步者上安装 runipy,我需要 python。 But when i want to run the.gitlab-ci.yml script it gets stuck at printing the python version because python is not recognized.但是当我想运行 .gitlab-ci.yml 脚本时,它会卡在打印 python 版本,因为 python 无法识别。

.gitlab-ci.yml: .gitlab-ci.yml:

image: python:3.9

before_script:
  - python -V
  - pip install runipy

error:错误:

Running with gitlab-runner 13.3.1 (738bbe5a)
  on JavaUnitTestRunner vr_SgzNd
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on DESKTOP-DJVC49J...
Getting source from Git repository
00:03
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/Gitlab-Runner/builds/vr_SgzNd/0/I438220/pharma/.git/
Checking out 65a225c0 as pipeline...
git-lfs/2.9.2 (GitHub; windows amd64; go 1.12.7; git 0274d856)
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ python -V
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
 the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\WINDOWS\TEMP\build_script377697220\script.ps1:195 char:1
+ python -V
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
ERROR: Job failed: exit status 1

When i try the same command in cmd everything works just fine.当我在 cmd 中尝试相同的命令时,一切正常。

Based on your log, you're using the shell executor.根据您的日志,您使用的是shell执行程序。 This will run commands on your local shell, just like you would yourself.这将在您的本地 shell 上运行命令,就像您自己一样。 The problem is the runner does not use your OS environment variables, so you need to add your python , git , etc. paths to the runner's path environment variable.问题是跑步者不使用你的操作系统环境变量,所以你需要将你的pythongit等路径添加到跑步者的路径环境变量中。

The best way to do this is to configure the path variables explicitly in the environment variable in the [[runners]] section of your runner's config.toml .最好的方法是在运行器config.toml[[runners]]部分的environment变量中显式配置路径变量。 The config.toml file can either be in /etc/gitlab-runner/ , ~/.gitlab-runner or / root. config.toml文件可以在/etc/gitlab-runner/~/.gitlab-runner/ root 中。 This StackOverflow thread shows how to do this.这个 StackOverflow 线程展示了如何做到这一点。 Please read Advanced Configurations for more info.请阅读高级配置以获取更多信息。

If you want to download and use a custom docker image, like python:3.9 , you need to use the Docker Executor .如果要下载并使用自定义 docker 映像,例如python:3.9 ,则需要使用Docker 执行器

If you are using Windows Server, make sure that the environment variables are defined in the system section, Python sets these items in the user section by default.如果您使用的是 Windows 服务器,请确保在系统部分中定义了环境变量,Python 默认在用户部分中设置这些项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM