source python script in R

I'm trying to import a python script via reticulate package into R (shiny app) :

# Define any Python packages needed for the app here:
PYTHON_DEPENDENCIES = c('pip', 'numpy')

virtualenv_dir = Sys.getenv('VIRTUALENV_NAME')
python_path = '/opt/python/3.10.2/bin/python3.10'
  
  # Create virtual env and install dependencies
  reticulate::virtualenv_create(envname = virtualenv_dir, python = python_path)
  reticulate::virtualenv_install(virtualenv_dir, packages = PYTHON_DEPENDENCIES, ignore_installed=TRUE)
  reticulate::use_virtualenv(virtualenv_dir, required = T)

  
  # Import python functions to R
  reticulate::source_python('python_functions.py')

But then Running the last line source_python will return the error :

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/opt/python/miniconda/lib/python3.9/site-packages/conda/exceptions.py", line 1080, in __call__
        return func(*args, **kwargs)
      File "/opt/python/miniconda/lib/python3.9/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/opt/python/miniconda/lib/python3.9/site-packages/conda/cli/conda_argparse.py", line 83, in do_call
        return getattr(module, func_name)(args, parser)
      File "/opt/python/miniconda/lib/python3.9/site-packages/conda/cli/main_run.py", line 25, in execute
        script_caller, command_args = wrap_subprocess_call(on_win, context.root_prefix, prefix,
      File "/opt/python/miniconda/lib/python3.9/site-packages/conda/utils.py", line 403, in wrap_subprocess_call
        with Utf8NamedTemporaryFile(mode='w', prefix=tmp_prefix, delete=False) as fh:
      File "/opt/python/miniconda/lib/python3.9/site-packages/conda/auxlib/compat.py", line 88, in Utf8NamedTemporaryFile
        return NamedTemporaryFile(
      File "/opt/python/miniconda/lib/python3.9/tempfile.py", line 541, in NamedTemporaryFile
        (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
      File "/opt/python/miniconda/lib/python3.9/tempfile.py", line 251, in _mkstemp_inner
        fd = _os.open(file, flags, 0o600)
    PermissionError: [Errno 13] Permission denied: '/opt/python/3.10.2/.tmpn2kwx5t2'

`$ /opt/python/miniconda/bin/conda run --prefix /opt/python/3.10.2 --no-capture-output python -c import os; print(os.environ['PATH'])`

  environment variables:
                 CIO_TEST=<not set>
             CONDA_PREFIX=/opt/python/3.10.2
               CONDA_ROOT=/opt/python/miniconda
           CURL_CA_BUNDLE=<not set>
          LD_LIBRARY_PATH=/opt/R/4.1.2/lib/R/lib:/lib:/usr/local/lib:/usr/lib/x86_64-linux-
                          gnu:/usr/lib/jvm/java-11-openjdk-amd64/lib/server
                     PATH=/opt/python/miniconda/condabin:/opt/python/3.10.2/bin:/opt/python/2.7.
                          16/bin:/opt/python/3.10.2/bin:/opt/python/3.9.0/bin:/opt/python/3.7.7/
                          bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap
                          /bin:/bin:/usr/lib/rstudio-server/bin/postback
              PYTHON_PATH=python3
       REQUESTS_CA_BUNDLE=<not set>
   RMARKDOWN_MATHJAX_PATH=/usr/lib/rstudio-server/resources/mathjax-27
   RS_MONITOR_SOCKET_PATH=/var/run/rstudio-server/rstudio-rserver/rserver-monitor.socket
        RS_RPOSTBACK_PATH=/usr/lib/rstudio-server/bin/rpostback
RS_SERVER_LOCAL_SOCKET_PATH=/var/run/rstudio-server/rstudio-rserver/rserver.socket
RS_SERVER_RPC_SOCKET_PATH=/var/run/rstudio-server/rstudio-rserver/session-server-rpc.socket
            SSL_CERT_FILE=<not set>

     active environment : /opt/python/3.10.2
    active env location : /opt/python/3.10.2
       user config file : /home/a2bgf93/.condarc
 populated config files : 
          conda version : 4.11.0
    conda-build version : not installed
         python version : 3.9.7.final.0
       virtual packages : __linux=5.13.0=0
                          __glibc=2.31=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /opt/python/miniconda  (read only)
      conda av data dir : /opt/python/miniconda/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /opt/python/miniconda/pkgs
                          /home/a2bgf93/.conda/pkgs
       envs directories : /home/a2bgf93/.conda/envs
                          /opt/python/miniconda/envs
               platform : linux-64
             user-agent : conda/4.11.0 requests/2.27.1 CPython/3.9.7 Linux/5.13.0-1017-azure ubuntu/20.04.3 glibc/2.31
                UID:GID : 1962704655:1102800513
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.

Error in Sys.setenv(PATH = new_path) : wrong length for argument
In addition: Warning message:
In system2(conda, c("run", in_env, run_args, shQuote(cmd), args),  :
  running command ''/opt/python/miniconda/bin/conda' run --prefix '/opt/python/3.10.2' --no-capture-output 'python' -c "import os; print(os.environ['PATH'])"' had status 1

And the permission denied on the python folder, I don't really know where it comes from ! :

:/opt/python# ls -la
total 73888
drwxr-xr-x  7 root root       97 Mar  8 14:08 .
drwxr-xr-x  9 root root       99 Apr  4 21:17 ..
drwxr-xr-x  9 root root      108 Mar  8 13:55 2.7.16
drwxr-xr-x 13 root root      195 Mar 15 17:37 3.10.2
drwxr-xr-x 12 root root      184 Mar 15 17:27 3.7.7
drwxr-xr-x 12 root root      184 Mar 15 17:33 3.9.0
drwxr-xr-x 16 root root      256 Mar  8 13:19 miniconda
-rwxr-xr-x  1 root root 75660608 Mar  8 13:18 miniconda.sh

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.