Publishing to with Python3

Hi everyone,

I am trying to publish a shinyApp with Python3 to 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.


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

1 Like

Hi @cpsievert,

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

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:


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
2019-09-13T12:37:01.961277+00:00 shinyapps[1190338]: Collecting pip
2019-09-13T12:37:02.307779+00:00 shinyapps[1190338]:   Using cached
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
2019-09-13T12:37:02.816728+00:00 shinyapps[1190338]:   Using cached
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
2019-09-13T12:37:05.489669+00:00 shinyapps[1190338]: Collecting pandas
2019-09-13T12:37:05.767222+00:00 shinyapps[1190338]:   Downloading (10.1MB)
2019-09-13T12:37:07.730605+00:00 shinyapps[1190338]:   Downloading (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 (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 (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 (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 (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
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
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 (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?

Hi there, Is anyone came up with a Solution? I'm getting the same error. All we need is python 3 but for somereason by default it's python2.

virtualenv_create(envname = "pyDev",python = "python")
virtualenv_install(envname = "pyDev", packages = c('pandas','numpy','plotly'))
reticulate::use_virtualenv("pyDev", required = TRUE)

pandas = import('pandas')

The development version of reticulate attempts to address this issue.

1 Like

Take a look at this tutorial -> Tutorial: using Shiny + reticulate to create apps with R and Python 3. It might be of help

1 Like