简体   繁体   English

为Travis构建安装Python和R?

[英]Installing both Python and R for a Travis build?

I've been working on an R package which interfaces with Python via a simple server script and socket connections. 我一直在研究一个R包,它通过一个简单的服务器脚本和套接字连接与Python连接。 I can test in on my own machine just fine, but I'd like to test it on a Travis build as well (I don't want to go through the effort of setting up a Linux VM). 我可以在我自己的机器上测试,但我也想在Travis构建上测试它(我不想完成设置Linux VM的工作)。 To do this I would need a Python install that I can pass the path to in my R package tests, and a port number to use. 要做到这一点,我需要一个Python安装,我可以在我的R包测试中传递路径,以及要使用的端口号。

I've seen this answer which suggests installing multiple Python builds is possible, but I'm not sure how to approach 我已经看到这个答案 ,建议安装多个Python构建是可能的,但我不知道如何处理

  1. Specifying the path(s) to the Python executable(s) 指定Python可执行文件的路径
  2. choosing a port number for the test. 选择测试的端口号。 It should also be noted that the Python script I am using for the Python 'server' uses 'localhost'. 还应该注意,我用于Python'服务器'的Python脚本使用'localhost'。

Is it possible to do what I want on Travis? 是否有可能在特拉维斯做我想做的事情? Should I want to do this with Travis? 想与特拉维斯做到这一点?

EDIT Here's my Travis config: 编辑这是我的Travis配置:

language: r
r:
  - release
  - devel
cache: packages
sudo: false

matrix:
  include:
    - python:2.7
    - python:3.6

# Be strict when checking our package
warnings_are_errors: true

# System dependencies for HTTP calling
r_binary_packages:
 - jsonlite
 - R6

And here is the example in my R package: 以下是我的R包中的示例:

pypath = Sys.which('python') 
if(nchar(pypath) > 0) {
  py = PythonEnv$new(port = 6011, path = pypath)
  py$start
  py$running
  py$set(a = 5)
  py$get('a')
  py$stop
} else {
  message("No Python environment available")
}

My example definitely finds a Python path, but fails with the error 我的例子肯定找到了一条 Python路径,但是因错误而失败

Warning in socketConnection(port = self$port, open = "r+", blocking = TRUE, : localhost:6011 cannot be opened socketConnection中的警告(port = self $ port,open =“r +”,blocking = TRUE,:localhost:6011无法打开

Error socketConnection(port = self$port, open = "r+", blocking = TRUE, : socketConnection错误(port = self $ port,open =“r +”,blocking = TRUE,:
cannot open the connection 无法打开连接

I tested this with another port and same error occurs. 我用另一个端口测试了这个,发生了同样的错误。

EDIT 2 编辑2

I've also tried it with host 127.0.0.1 and 0.0.0.0 but no dice. 我也尝试过主机127.0.0.10.0.0.0但没有骰子。 According to the Travis documentation, this should work... perhaps an issue with the R container? 根据Travis的文档,这应该有用......也许是R容器的一个问题?

Here is a travis.yml I use for my pyrle package. 这是我用于我的pyrle包的travis.yml。 It just installs R usinq the ubuntu package manager: 它只是安装R usinq的ubuntu包管理器:

language: python
python:
  - "3.6"
install:
  - pip install cython pytest hypothesis
  - sudo apt-get install -y r-base
  - echo 'source("https://bioconductor.org/biocLite.R"); biocLite("S4Vectors"); biocLite("GenomicRanges")' > install.R
  - python setup.py install

script:
  - py.test tests/

Another way is to install R through conda. 另一种方法是通过conda安装R. Here is an example from the pyranges package: 以下是pyranges包中的示例:

# Stolen from http://conda.pydata.org/docs/travis.html
language: python
python:
  # We don't actually use the Travis Python, but this keeps it organized.
  - "3.6"
install:
  - sudo apt-get update
  # We do this conditionally because it saves us some downloading if the
  # version is the same.
  - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
  - bash miniconda.sh -b -p $HOME/miniconda
  - export PATH="$HOME/miniconda/bin:$PATH"
  - hash -r
  - conda config --set always_yes yes --set changeps1 no
  - conda update -q conda
  - conda config --add channels bioconda
  - conda config --add channels r
  # Useful for debugging any issues with conda
  - conda info -a
  - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy pandas pytest pytest-cov cython tabulate hypothesis bedtools # ray
  - source activate test-environment
  - python setup.py install # will install ncls
  - python --version
  - python -c 'import pandas as pd; print(pd.__version__)'
  - ls tests

script: py.test -v tests # verbose to see that tests run and so that travis does not time out on hypothesis tests

Your question title and question body are quite different. 你的问题标题和问题正文是完全不同的。

Regarding the python+R Question 关于python + R问题

Similarly to The Unfun Cat's answer which uses travis to install python and installs R with apt, you can use travis for R and install python with apt: Unfun Cat的回答类似,使用travis安装python并使用apt安装R,你可以使用travis for R并使用apt安装python:

language: r
install:
  - sudo apt-get install -y python2.7 python3.6

Note that travis also has an apt addon which makes your .yaml a bit cleaner (but arguably less portable). 请注意,travis还有一个apt插件 ,使你的.yaml更清洁(但可以说是便携性更低)。

language: r
addons:
  apt:
    packages:
    - python2.7
    - python3.6

The different python versions installed should be accessible to Sys.which as python2.7 and python3.6 instead of just "python". 安装的不同python版本应该可以被Sys.which访问为python2.7python3.6而不仅仅是“python”。 which python will return either the last version installed or else the last installed python2* . which python将返回最后安装的版本或者最后安装的python2*


Regarding the networking question 关于网络问题

There are a number of reasons a you may be unable to establish a connection. 您可能无法建立连接的原因有很多。 A common reason is that the port is already in use. 一个常见的原因是端口已经在使用中。 Port 6011 is sometimes used by the X window system ( ref ), so it is possible a one of travis's services is using it. 端口6011有时被X窗口系统( ref )使用,因此travis的服务之一可能正在使用它。

Using this reference on how to check for used ports you might try adding something like 使用此参考如何检查已使用的端口,您可以尝试添加类似的东西

sudo lsof -i -P -n | grep LISTEN | grep 6011

to your travis.yaml so you can see in the log if the port is used. 到你的travis.yaml所以你可以在日志中看到是否使用了端口。 You might also try a different unused port number in your script. 您也可以在脚本中尝试使用其他未使用的端口号。

I did find this github comment referencing similar issues with R specifically; 我确实发现这个github评论引用了与R类似的问题; perhaps you can find more there. 也许你可以在那里找到更多。

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

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