Support

Troubleshooting Python with RStudio Connect

Follow

General errors when using system version of Python

Error:

General Python errors when deployed Python content to RStudio Connect (i.e., apps or documents that use the reticulate package or Jupyter Notebooks).

Most of the issues encountered with Python and RStudio Connect occur when trying to use the version of Python that is included with the system (typically located at /usr/bin/python).

Solution:

Ensure that you are using a version of Python that was installed from source (typically located in /opt/Python/X.Y.Z) as recommended in the RStudio Connect admin guide (followed by installing pip and virtualenv) instead of the version of Python included with the system.

Installing Python from source will result in a standalone Python environment that is separate from the system/framework installation of Python that won't be affected when you update system packages.

This also allows you to install and use multiple versions of Python with RStudio Connect that can be used by different published content/apps.

 


 

Mismatched / expected version errors when using Python installed from source

Error:

The following error can occur with RStudio Connect 1.7.0 when using a Python installation from source (typically in /opt/Python/X.Y.Z/) when a similar version of Python exists on the system (typically at /usr/bin/python).

The Python installation in the environment was expected to have
version 3.6.8 but is reporting version 3.6.7 ; the Python
installation for version 3.6.8 may have changed. RStudio Connect
needs to be restarted. Please contact the server administrator.

In the above example, this error was generated when deploying Python content to RStudio Connect on Ubuntu 18.04 with a system version of Python 3.6.7 and a version of Python 3.6.8 installed from source.

This error occurs due to an issue with virtualenv behavior and how Python is configured to use shared libraries at runtime.

Solution:

Compile Python from source with the additional --disable-new-dtags flag during the configure step in the RStudio Connect documentation steps to Build Python from Source.

The corrected configure command to use is as follows:

./configure \
--prefix=/opt/Python/${VERSION} \
--enable-shared \
--enable-ipv6 \
LDFLAGS=-Wl,-rpath=/opt/Python/${VERSION}/lib,--disable-new-dtags

 


 

NameError when deploying Python content to RStudio Connect

Error:

You may encounter the following error when deploying Python content to RStudio Connect:

2019/01/25 22:57:41.173653408 label: setup
2019/01/25 22:57:44.527159916 Quitting from lines 12-16 (demo-notebook.Rmd)
2019/01/25 22:57:44.527336538 Error in py_initialize(config$python, config$libpython, config$pythonhome, :
2019/01/25 22:57:44.527339368 NameError: name 'prev' is not defined
2019/01/25 22:57:44.527357490
2019/01/25 22:57:44.527358374 Detailed traceback:
2019/01/25 22:57:44.527368749 File "<string>", line 46, in <module>
2019/01/25 22:57:44.527369751 File "<string>", line 46, in <listcomp>
2019/01/25 22:57:44.527377233 Calls: local ... ensure_python_initialized -> initialize_python -> py_initialize -> .Call
2019/01/25 22:57:44.527436361 In addition: Warning message:
2019/01/25 22:57:44.527549465 In res[i] = withCallingHandlers(if (tangle) process_tangle(group) else process_group(group), :
2019/01/25 22:57:44.527589661 number of items to replace is not a multiple of replacement length
2019/01/25 22:57:44.528223479
2019/01/25 22:57:44.528973397 Execution halted
Task: uj2MsY07KM2RSc9L Rendering exited abnormally: exit status 1 

Solution:

A workaround is to downgrade to virtualenv 16.1.0 and remove the associated Python environments in /var/lib/rstudio-connect/python-environments by running the following commands:

sudo /opt/Python/X.Y.Z/bin/pip install virtualenv==16.1.0
rm -rf /var/lib/rstudio-connect/python-environments/

where X.Y.Z is the version of Python you are using.

 


 

Error with reticulate when deploying Python content to RStudio Connect

Error:

* reticulate is in use, but python was not specified
Execution halted

Solution:

This error indicates that your app or document uses Python via the reticulate package, but your RStudio IDE is not configured to point to a Python environment to use for local testing and publishing.

Instead of using the reticulate::use_* group of functions, we recommend using the RETICULATE_PYTHON environment variable on your local machine to publish apps and documents with Python content to RStudio Connect using the push-button publishing functionality of the RStudio IDE.

Refer to the support article on Using Python with RStudio Connect for more information on how to configure this environment variable.


 

SSL errors when using Python installed from source

Error:

The following errors can occur after installing Python from source, such as when installing pip into the Python environment.

pip is configured with locations that require TLS/SSL,
however the ssl module in Python is not available.
Retrying (Retry(total=1, connect=None, read=None, redirect=None,
status=None)) after connection broken by 'SSLError("Can't connect
to HTTPS URL because the SSL module is not available.")':
/simple/pip

And the following error occurs when you attempt to import the ssl library in the version of Python that was installed from source:

$ /opt/Python/3.7.1/bin/python
Python 3.7.1 (default, Nov 29 2018, 16:28:02)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/Python/3.7.1/lib/python3.7/ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

Solution:

Verify that Python was installed correctly from source following the Installing Python steps in the RStudio Connect admin guide, including the steps to install pip and virtualenv.

Ensure that you defined the VERSION and PY_VERSION environment variables with the desired version of Python when following the installation steps.

Ensure that Python is installed in /opt/Python/2.x.x, or /opt/Python/3.x.x depending on the version of Python that you installed.

You can verify that your Python installation is working by running the following commands to import the SSL library (for Python 3.7.1 in this example):

$ /opt/Python/3.7.1/bin/python
Python 3.7.1 (default, Nov 29 2018, 16:28:02)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>

Comments