Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need way of setting mirrors / alternate download locations for install and packages #1708

Open
Axel-Shark opened this issue Jan 3, 2025 · 2 comments

Comments

@Axel-Shark
Copy link

My org blocks https://www.python.org/ftp/python so reticulate commands like install_python() and py_install() fail since they're hitting https://www.python.org/ftp/python by default.

We have internal mirrors for all of the sources but I don't see any mention in the reticulate MAN for how to define alternate sources / mirrors

@t-kalinowski
Copy link
Member

You can point pip at your org's mirror by setting an env var like

PIP_INDEX_URL=https://<custom-mirror-url>

or by creating a global pip.conf file with the index-url set. That should work for py_install() and virtualenv_create()/virtualenv_install(), but I'm not sure about install_python().

You might also be able to use the Posit package manager, using the setup instructions here:
https://packagemanager.posit.co/client/#/repos/pypi/setup

@Axel-Shark
Copy link
Author

Axel-Shark commented Jan 3, 2025

Thank you! I'm new to Python and hadn't come across any of these options while looking for an answer. This looks promising!

EDIT: the solution offered by @t-kalinowski may be an option, but this is what I ended up doing in case someone finds themselves in a similar situation. I found that Posit mirrors PyPi and isn't blocked by my company's firewall.

system('wget <URL to Miniconda3-latest-Linux-x86_64.sh> -O ~/miniconda.sh') # download latest version of miniconda
system('bash ~/miniconda.sh -b -u -p ~/miniconda3') # install miniconda
system('rm -rf ~/miniconda.sh') # remove miniconda installer
system('~/miniconda3/bin/conda init bash') # activate conda for bash
system('~/miniconda3/bin/conda init zsh') # activate conda for zsh

library(reticulate)

# confirm that miniconda is installed
conda_list()
use_python(<use path returned by conda_list()>)

# use Posit Package Manager instead of PyPi / Python official repo
system('pip config set global.index-url https://packagemanager.posit.co/pypi/latest/simple')
system('pip config set global.trusted-host packagemanager.posit.co')

py_install("numpy", pip = TRUE) # confirm install is possible now. pip = TRUE is essential!!
# NB all Python libraries will be installed to your miniconda environment, so make sure you set the right one with use_python()

# run Python in R
np <- import("numpy", convert = TRUE)
np1 <- np$array(c(1:4))
np1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants