Sage-Bionetworks / synapser

An R package providing programmatic access to Synapse
Apache License 2.0
32 stars 21 forks source link

pip.main returned 1 when installing synapseclient==2.2.2 #293

Closed ArtemSokolov closed 3 years ago

ArtemSokolov commented 3 years ago

Operating system and R/tidyverse environment

Ubuntu 20.04 LTS R 4.0.1 tidyverse 1.3.0

Description of the problem

Installing the package raises the following exception:

Command "/usr/local/lib/R/site-library/PythonEmbedInR/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-h7p9rsdy/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-qm7qj3cw/install-record.txt --single-version-externally-managed --compile --home=/tmp/pip-target-jfbt0sgm" failed with error code 1 in /tmp/pip-install-h7p9rsdy/cryptography/
You are using pip version 18.1, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "/tmp/RtmpwDzp01/R.INSTALL2fba53de384b/synapser/inst/python/installPythonClient.py", line 129, in main

_install_pip(["synapseclient=={}".format(SYNAPSE_CLIENT_PACKAGE_VERSION)], localSitePackages)
  File "/tmp/RtmpwDzp01/R.INSTALL2fba53de384b/synapser/inst/python/installPythonClient.py", line 175, in _install_pip

raise Exception("pip.main returned {} when installing {}".format(rc, package))
Exception
:
pip.main returned 1 when installing synapseclient==2.2.2
Error in PythonEmbedInR::pyExec(command) :
  An error has occurred while executing Python code. See traceback above.
Execution halted
ERROR: configuration failed for package ‘synapser’
* removing ‘/usr/local/lib/R/site-library/synapser’

The downloaded source packages are in
        ‘/tmp/RtmpJnuoIE/downloaded_packages’
Warning message:
In install.packages("synapser", repos = c("http://ran.synapse.org",  :
  installation of package ‘synapser’ had non-zero exit status

The issue can be reproduced with a Docker container:

$ docker run --rm -it rocker/tidyverse:4.0.1 /bin/bash
root@0cd3d28b5e97:/# R -e 'install.packages( "synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org") )'
jkiang13 commented 3 years ago

Thanks @ArtemSokolov

It looks like this is caused by a recent change to the Python cryptography library which is a dependency of the Synapse client and requires a Rust compiler to be available to compile from source as of a new release a few days ago.

We will need to release a new version of synapser to improve its compatibility due to this change. In the meantime a workaround is setting the following environment variable before installing synapser: export CRYPTOGRAPHY_DONT_BUILD_RUST=true

ArtemSokolov commented 3 years ago

The workaround works great! Thanks very much.

QuanWan89 commented 3 years ago

Hi, the workaround still doesn't work for me.

QuanWan89 commented 3 years ago

Traceback (most recent call last): File "", line 1, in File "/tmp/RtmpeS1o1d/R.INSTALL3711447135ba/synapser/inst/python/installPythonClient.py", line 129, in main

_install_pip(["synapseclient=={}".format(SYNAPSE_CLIENT_PACKAGE_VERSION)], localSitePackages) File "/tmp/RtmpeS1o1d/R.INSTALL3711447135ba/synapser/inst/python/installPythonClient.py", line 175, in _install_pip

raise Exception("pip.main returned {} when installing {}".format(rc, package)) Exception : pip.main returned 1 when installing synapseclient==2.2.2 Error in PythonEmbedInR::pyExec(command) : An error has occurred while executing Python code. See traceback above. Execution halted ERROR: configuration failed for package ‘synapser’

jkiang13 commented 3 years ago

@QuanWan89 can you indicate what platform (Linux distribution and version or Docker image) you are encountering the issue on? The above workaround for now continues to work across the platforms that I tested.

e.g.

export CRYPTOGRAPHY_DONT_BUILD_RUST=true
R -e 'install.packages( "synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org") )'
QuanWan89 commented 3 years ago

Hi, it is a docker image. Within the container: PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" VERSION_CODENAME=stretch ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 9.11 (stretch) Release: 9.11 Codename: stretch

jkiang13 commented 3 years ago

@QuanWan89 can you show the Dockerfile or indicate the base image? Is it debian:stretch?

QuanWan89 commented 3 years ago

If I remember correctly, it may use rocker/rstudio:3.6

jkiang13 commented 3 years ago

@QuanWan89 I am able to install using rocker/rstudio:3.6 and the above workaround. On a base rocker/rstudio:3.6 I did have to apt-get install zlib1g-dev first (zlib-dev being a current SystemRequirement in the DESCRIPTION file)

e.g. docker run -ti rocker/rstudio:3.6 /bin/bash

apt-get install zlib1g-dev
export CRYPTOGRAPHY_DONT_BUILD_RUST=true
R -e 'install.packages( "synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org") )'
thomasyu888 commented 3 years ago

When writing a Dockerfile, you need to have:

ENV CRYPTOGRAPHY_DONT_BUILD_RUST=true

Doing the export will not work.

RUN export CRYPTOGRAPHY_DONT_BUILD_RUST=true
jkiang13 commented 3 years ago

You can also set a local environment variable for the installation command only. This should work inside or outside of a Dockerfile, e.g.

CRYPTOGRAPHY_DONT_BUILD_RUST=true R -e 'install.packages( "synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org") )

or inside a Dockerfile:

RUN CRYPTOGRAPHY_DONT_BUILD_RUST=true R -e 'install.packages( "synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org") )

ArtemSokolov commented 3 years ago

If helpful, here's a fully functioning Dockerfile that installs synapser as well as my extensions that streamline its usage in functional programming: https://github.com/ArtemSokolov/synExtra/blob/docker/Dockerfile

Download the Dockerfile and build the container image with docker build -t test . Example usage after the image is built:

$ docker run -it --rm test /bin/bash

root@c54d8ae131d4:/# R -q

> synapser::synLogin( <username>, <password> )
Welcome, Artem Sokolov!NULL

> synExtra::synName( "syn1896429", "syn1901530" )
                             syn1896429                              syn1901530
         "ESTIMATE_scores_PANCAN11.tsv" "ESTIMATE_scores_PANCAN11_RNASeqV2.tsv"
jkiang13 commented 3 years ago

synapser 0.10 resolves this issue. It can be installed as normal. install.packages("synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org"))