Publishing to ShinyApps.io with Python3

Hi everyone,

I am trying to publish a shinyApp with Python3 to shinyApps.io. According to this post, I added the code below on my App.R file.

virtualenv_create('pyDev',python = 'python3')
virtualenv_install("pyDev", packages = c('gensim', 'pandas','numpy','nltk','paramiko'))
reticulate::use_virtualenv("pyDev", required = TRUE)

However, when I publish the app, I got the following error:

Required version of Python '~/.virtualenvs/pyDev/bin/python' cannot be used because another version of Python ('/usr/bin/python') is already initialized for this process.
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>

However, I can still open the published application, but it will "disconnect from server" whenever it tries to run python codes.
I checked the log and the app is actually still running on Python2.7. Anyone know how to resolve this? Thanks in advance, I appreciate your help.

Marshal

1 Like

Hi @Marshal, did you also trying installing this version of rsconnect (before deploying)?

devtools::install_github("rstudio/rsconnect", ref='737cd48')

Regardless, it'd would be great if you could also report this issue here https://github.com/rstudio/rsconnect

Hi @cpsievert,

Thanks for replying. Yes, I tried. Without it there is another error. Sure, I am happy to post the issue.

1 Like

Hello. I am having the same problem exactly. Did you succeed in running python3? Thank you.

Hi there,

No. Unfortunately it still remains unsolved.

Thank you. For the record, I have also been trying another approach mentioned around with use_python(), with no luck either. Yet, Python3 seems to be there, one can get the path using which.

I am also having issues with this.
I have now tried creating an app with the following configuration

reticulate::virtualenv_create(envname = "pyDev", python="/usr/bin/python3")
reticulate::use_virtualenv("pyDev", required = TRUE)
reticulate::virtualenv_install(envname = "pyDev", packages = c('pandas', 'elasticsearch_dsl'))

and a .Renviron file with the following in:

RETICULATE_PYTHON=/home/shiny/.virtualenvs/pyDev/bin/python

This gives the following output in the log:

2019-09-13T12:36:56.622043+00:00 shinyapps[1190338]: Creating virtual environment 'pyDev' ...
2019-09-13T12:36:56.622045+00:00 shinyapps[1190338]: Using python: /usr/bin/python3
2019-09-13T12:36:57.046814+00:00 shinyapps[1190338]: New python executable in /home/shiny/.virtualenvs/pyDev/bin/python2
2019-09-13T12:36:57.046817+00:00 shinyapps[1190338]: Also creating executable in /home/shiny/.virtualenvs/pyDev/bin/python
2019-09-13T12:37:01.150268+00:00 shinyapps[1190338]: Installing setuptools, pkg_resources, pip, wheel...done.
2019-09-13T12:37:01.157031+00:00 shinyapps[1190338]: Running virtualenv with interpreter /usr/bin/python2
2019-09-13T12:37:01.747428+00:00 shinyapps[1190338]: DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
2019-09-13T12:37:01.961277+00:00 shinyapps[1190338]: Collecting pip
2019-09-13T12:37:02.307779+00:00 shinyapps[1190338]:   Using cached https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl
2019-09-13T12:37:02.396932+00:00 shinyapps[1190338]: Collecting wheel
2019-09-13T12:37:02.447274+00:00 shinyapps[1190338]: Collecting setuptools
2019-09-13T12:37:02.440098+00:00 shinyapps[1190338]:   Using cached https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl
2019-09-13T12:37:02.816728+00:00 shinyapps[1190338]:   Using cached https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl
2019-09-13T12:37:02.861067+00:00 shinyapps[1190338]: Installing collected packages: pip, wheel, setuptools
2019-09-13T12:37:04.138965+00:00 shinyapps[1190338]: Successfully installed pip-19.2.3 setuptools-41.2.0 wheel-0.33.6
2019-09-13T12:37:04.336226+00:00 shinyapps[1190338]: Using virtual environment 'pyDev' ...
2019-09-13T12:37:05.385320+00:00 shinyapps[1190338]: DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
2019-09-13T12:37:05.489669+00:00 shinyapps[1190338]: Collecting pandas
2019-09-13T12:37:05.767222+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/db/83/7d4008ffc2988066ff37f6a0bb6d7b60822367dcb36ba5e39aa7801fda54/pandas-0.24.2-cp27-cp27mu-manylinux1_x86_64.whl (10.1MB)
2019-09-13T12:37:07.730605+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/77/95/aa96ac42bf7cf8d56d4c7330f4fa5c1b2c460efa7ad2e9ba183bae823b0b/elasticsearch_dsl-7.0.0-py2.py3-none-any.whl (48kB)
2019-09-13T12:37:07.750942+00:00 shinyapps[1190338]: Collecting python-dateutil>=2.5.0 (from pandas)
2019-09-13T12:37:07.781024+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
2019-09-13T12:37:07.704764+00:00 shinyapps[1190338]: Collecting elasticsearch_dsl
2019-09-13T12:37:07.795053+00:00 shinyapps[1190338]: Collecting numpy>=1.12.0 (from pandas)
2019-09-13T12:37:08.202619+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/d7/b1/3367ea1f372957f97a6752ec725b87886e12af1415216feec9067e31df70/numpy-1.16.5-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)
2019-09-13T12:37:11.282738+00:00 shinyapps[1190338]: Collecting pytz>=2011k (from pandas)
2019-09-13T12:37:11.448202+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/87/76/46d697698a143e05f77bec5a526bf4e56a0be61d63425b68f4ba553b51f2/pytz-2019.2-py2.py3-none-any.whl (508kB)
2019-09-13T12:37:11.564406+00:00 shinyapps[1190338]: Collecting elasticsearch<8.0.0,>=7.0.0 (from elasticsearch_dsl)
2019-09-13T12:37:11.611324+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/df/63/86cfe50a11621240450322509f8eacac14f3381cbf43aee2fe56db8c7c8a/elasticsearch-7.0.4-py2.py3-none-any.whl (83kB)
2019-09-13T12:37:11.636289+00:00 shinyapps[1190338]: Collecting six (from elasticsearch_dsl)
2019-09-13T12:37:11.661218+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
2019-09-13T12:37:11.666320+00:00 shinyapps[1190338]: Collecting ipaddress; python_version < "3.3" (from elasticsearch_dsl)
2019-09-13T12:37:11.695586+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
2019-09-13T12:37:11.810774+00:00 shinyapps[1190338]: Installing collected packages: six, python-dateutil, numpy, pytz, pandas, urllib3, elasticsearch, ipaddress, elasticsearch-dsl
2019-09-13T12:37:11.700895+00:00 shinyapps[1190338]: Collecting urllib3>=1.21.1 (from elasticsearch<8.0.0,>=7.0.0->elasticsearch_dsl)
2019-09-13T12:37:11.747467+00:00 shinyapps[1190338]:   Downloading https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl (150kB)
2019-09-13T12:37:17.833212+00:00 shinyapps[1190338]: Successfully installed elasticsearch-7.0.4 elasticsearch-dsl-7.0.0 ipaddress-1.0.22 numpy-1.16.5 pandas-0.24.2 python-dateutil-2.8.0 pytz-2019.2 six-1.12.0 urllib3-1.25.3
2019-09-13T12:37:19.055096+00:00 shinyapps[1190338]: 

It therefore seems to blatantly ignore that I want a Python 3. The app does however run with the installed packages as intended. It is just a Python 2 installation instead of Python 3.

Any suggestions for how to fix this?