Conda env and Plone

Hi,
I have miniconda installed in my system. How can let Plone use packages installed in one of conda evns?

When I start Plone command line using bin/instance debug in any conda evn and try to see the installed packages by
os.system('pip list')

I can see the packages installed in this evn. However, when I import some installed packages, such as pandas, I got error: No module named 'pandas'. Why is that?

Thanks,

peijun

Plone typically uses buildout to build its Python environment. One buildout aim is to ensure an isolated virtual environment - with few dependencies on other Python installations.

When you run buildout, typically scripts are generated in the bin directory. Those scripts extend Python's sys.path near their beginning and thereby provide access to the configured "eggs". Extend those "eggs" definitions to include all packages you need for your Plone installation; then rerun buildout (to get new scripts with the new packages generated).

buildout typically does not control the envvar PATH. It is this envvar which controls how shell commands are found. That's why os.system("pip ...") locates your system Python, not that used by the buildout installation.

buildout sits on top of a Python installation. Typically, this is a virtual env. You may install packages in this installation and Plone may be able to access them. However, I made the experience that (likely due to a Python bug) namespace packages (those are packages with "distributed" subpackages) can make problems when some subpackage of a namespace package is installed in the Python installation and other subpackgaes are installed via buildout. That's why I started to avoid this.

Could this be a requirements for some add-on that you are using. Pandas is a python package, read more here: pandas (software) - Wikipedia

Plone is not published as Conda packages. Anyway, you can use a Conda enviroment to install Plone inside. If Pandas is installed in the same enviroment it is available inside Plone as well.
Thus said, there are always two paths to go :wink:

  1. You can use Conda to install and run Buildout (given your buildout.cfg is located in the current directory):

    conda create --name plone52 python=3.8
    conda install -n plone52 pip
    conda activate plone52
    pip install -c https://dist.plone.org/release/5.2.3/requirements.txt zc.buildout
    buildout 
    bin/instance fg
    
  2. You can use Conda to just install Plone from using pip"

    conda create --name plone52 python=3.8
    conda install -n plone52 pip
    conda activate plone52
    pip install -c https://dist.plone.org/release/5.2.3/constraints.txt Plone Paste
    mkwsgiinstance -d .
    runwsgi -v etc/zope.ini
    

So, now with Pandas (using the #1 buildout variant with instance script):

$ conda install pandas
$ ./bin/instance debug
Starting debugger ...
>>> import pandas
>>> 

You will want to use https://dist.plone.org/release/5.2.3/constraints3.txt instead. This is almost the same as constraints.txt but has a few more recent packages that are only compatible with Python 3. This is the first time I created this file on dist.plone.org.

I think this need to be written in large bold neon letters on the wall.