PyCall problem

my julia version is 1.10.0, and my system is windows 10.

julia> using PyCall

julia> using JLD

julia> @pyimport sympy.physics.wigner  as wigner
ERROR: PyError (PyImport_ImportModule

The Python package sympy.physics.wigner could not be imported by pyimport. Usually this means
that you did not install sympy.physics.wigner in the Python version being used by PyCall.

PyCall is currently configured to use the Julia-specific Python distribution
installed by the Conda.jl package.  To install the sympy.physics.wigner module, you can
use `pyimport_conda("sympy.physics.wigner", PKG)`, where PKG is the Anaconda
package that contains the module sympy.physics.wigner, or alternatively you can use the
Conda package directly (via `using Conda` followed by `Conda.add` etcetera).

Alternatively, if you want to use a different Python distribution on your
system, such as a system-wide Python (as opposed to the Julia-specific Python),
you can re-configure PyCall with that Python.   As explained in the PyCall
documentation, set ENV["PYTHON"] to the path/name of the python executable
you want to use, run Pkg.build("PyCall"), and re-launch Julia.

I later installed sympy as

C:\Users\jmzhang>py -m pip install "sympy"

But the problem remains.

1 Like

oh, the problem is that ‘sympy.physics.wigner’ is not installed yet.

Installing ‘sympy’ does not imply its submodules included?

PS C:\Users\jmzhang> python 
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy.physis.wigner as wigner 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sympy.physis'

Are you sure PyCall is configured to use this python version? The error message says: PyCall is currently configured to use the Julia-specific Python distribution installed by the Conda.jl package (by default on Windows systems, PyCall installs its own Python distro via Conda.jl, entirely separate from any other Python installation on your system)

If you want it to use a different Python, e.g. the system-wide python program you’ve installed in your path, you need to configure PyCall to use this.

  1. restart julia
  2. set ENV["PYTHON"]="python" (assuming you want to use the python on your PATH)
  3. open the pkg> prompt (by typing ]') and then type build PyCall`

At that point you should be set (you only have to configure PyCall once).

2 Likes

It might not have installed into the place where Julia is looking for modules. You also misspelled physics as physis.

The original error message gave you a few suggestions. The one that looked appealing to me was:

Have you tried doing:

julia> ]
pkg> add Conda
pkg> <backspace>
julia> using Conda
julia> Conda.add("sympy")

?

I barely use python, so my previous post’s suggestion of using Conda.add didn’t work. However, you know what did work? From my shell:

conda add sympy

Then I could:

julia> @pyimport sympy.physics.wigner as wigner

…successfully.

1 Like

But how did you use conda? where to use it?

PS C:\Users\jmzhang> conda add sympy 
usage: conda-script.py [-h] [--no-plugins] [-V] COMMAND ...
conda-script.py: error: argument COMMAND: invalid choice: 'add' (choose from 'clean', 'compare', 'config', 'create', 'info', 'init', 'install', 'list', 'notices', 'package', 'remove', 'uninstall', 'rename', 'run', 
'search', 'update', 'upgrade', 'build', 'content-trust', 'convert', 'debug', 'develop', 'doctor', 'index', 'inspect', 'metapackage', 'render', 'skeleton', 'token', 'repo', 'verify', 'env', 'pack', 'server')        
PS C:\Users\jmzhang>

1 Like

I made a mistake in my post. I meant to say:

conda install sympy

I don’t know why I typed out “add”. Maybe I had “add” on my mind from the Julia’s Pkg.add(). Sorry about that.

1 Like