Problem installing SymPy on Windows 10 system

I am having difficulty installing SymPy. I keep getting the following error message after I type “using SymPy” into the REPL:

julia> using SymPy
[ Info: Installing sympy via the Conda sympy package…
[ Info: Running conda install -y sympy in root environment
failed to create process.
ERROR: InitError: PyError (PyImport_ImportModule

The Python package sympy could not be imported by pyimport. Usually this means
that you did not install sympy 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 module, you can
use pyimport_conda("sympy", PKG), where PKG is the Anaconda
package the contains the module sympy, 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.

) <class ‘ModuleNotFoundError’>
ModuleNotFoundError(“No module named ‘sympy’”)

Stacktrace:
[1] pyimport(name::String)
@ PyCall C:\Users\Richard Savage.julia\packages\PyCall\BD546\src\PyCall.jl:550
[2] pyimport_conda(modulename::String, condapkg::String, channel::String)
@ PyCall C:\Users\Richard Savage.julia\packages\PyCall\BD546\src\PyCall.jl:714
[3] pyimport_conda
@ C:\Users\Richard Savage.julia\packages\PyCall\BD546\src\PyCall.jl:707 [inlined]
[4] init()
@ SymPy C:\Users\Richard Savage.julia\packages\SymPy\VpBut\src\SymPy.jl:121
[5] _include_from_serialized(path::String, depmods::Vector{Any})
@ Base .\loading.jl:696
[6] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
@ Base .\loading.jl:782
[7] _require(pkg::Base.PkgId)
@ Base .\loading.jl:1020
[8] require(uuidkey::Base.PkgId)
@ Base .\loading.jl:936
[9] require(into::Module, mod::Symbol)
@ Base .\loading.jl:923
during initialization of module SymPy

I want to use the Julia-specific Python distribution
installed by the Conda.jl package. The error message says to use “pyimport_conda(“sympy”, PKG)” to install Sympy. What do I use for “PKG”?

Here is some additional info that may be relevant:
julia> Pkg.installed()
┌ Warning: Pkg.installed() is deprecated
└ @ Pkg C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\Pkg.jl:570
Dict{String, VersionNumber} with 19 entries:
“Hwloc” => v"2.0.0"
“Distributions” => v"0.25.11"
“Atom” => v"0.12.33"
“BenchmarkTools” => v"1.1.1"
“Interpolations” => v"0.13.3"
“TimerOutputs” => v"0.5.12"
“Juno” => v"0.8.4"
“Conda” => v"1.5.2"
“PyCall” => v"1.92.3"
“CalculusWithJulia” => v"0.0.7"
“SymPy” => v"1.0.50"
“Compat” => v"3.32.0"
“Plots” => v"1.15.2"
“GeometryBasics” => v"0.3.13"
“WebIO” => v"0.8.15"
“StaticArrays” => v"1.2.10"
“GLMakie” => v"0.4.4"
“DistributedArrays” => v"0.6.5"
“SpecialFunctions” => v"0.10.3"

julia> import Conda

julia> Conda.PYTHONDIR
“C:\Users\Richard Savage\.julia\conda\3”

julia> using PyCall

julia> PyCall.python
“C:\Users\Richard Savage\.julia\conda\3\python.exe”

From my understanding, the Python SymPy library will automatically be installed via conda when you first load the Julia SymPy package. However, if you look at the first three lines of output, this seems to fail in your case:

julia> using SymPy
[ Info: Installing sympy via the Conda sympy package…
[ Info: Running conda install -y sympy in root environment
failed to create process.

The subsequent error message from PyCall then tells you that it couldn’t import the sympy module, which isn’t surprising since it was never installed in the first place. So I don’t think it will help if you now manually do pyimport_conda("sympy", "sympy"), since this shouldn’t be any different from the failed attempt to install when loading the SymPy module before, and I would guess you will get the exact same error message.

Searching for the failed to create process. error on the web suggests that at some point in the past, there were difficulties when the name of the directory with the python installation contained a space (such as in your case, because of the user name). But that doesn’t seem to be a problem anymore, at least it worked without any problems for me on a Windows 10 system, with a fresh Julia 1.6 install and in a clean package environment, where I added nothing but the SymPy package.

So it is hard to say why you got an error, maybe there are remnants of an old python installation lying around, or some other packages are interfering. If you haven’t already, I would try to remove the SymPy package (and possibly also PyCall and Conda, in case you installed them separately) and reinstall it, sometimes that’s easier than trying to debug what went wrong at one of the later stages.

Also, do you still get an error if you create a new environment somewhere (e.g. via julia> cd("C:\\PROJECTPATH") followed by >pkg activate .) and add only the SymPy package?

The alternative would be to install your own python distribution and configure PyCall to use that instead.

bvrb - Thanks for replying to my post. I really appreciate it.

As you suggested, I removed Conda, PyCall and SymPy by using the Pkg.rm() command. Then I added SymPy as follows:
julia> Pkg.add(“SymPy”)
Updating registry at C:\Users\Richard Savage\.julia\registries\General
Updating git-repo https://github.com/JuliaRegistries/General.git
Resolving package versions…
Installed Conda ── v1.5.2
Installed SymPy ── v1.0.50
Installed PyCall ─ v1.92.3
Updating C:\Users\Richard Savage\.julia\environments\v1.6\Project.toml
[24249f21] + SymPy v1.0.50
Updating C:\Users\Richard Savage\.julia\environments\v1.6\Manifest.toml
[38540f10] + CommonSolve v0.2.0
[8f4d0f93] + Conda v1.5.2
[438e738f] + PyCall v1.92.3
[81def892] + VersionParsing v1.2.0
[81def892] + VersionParsing v1.2.0
[81def892] + VersionParsing v1.2.0
Building Conda ─→ C:\Users\Richard Savage\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\299304989a5e6473d985212c28928899c74e9421\build.log
Building PyCall → C:\Users\Richard Savage\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\169bb8ea6b1b143c5cf57df6d34d022a7b60c6db\build.log
Precompiling project…
2 dependencies successfully precompiled in 12 seconds (229 already precompiled)

So it looks like Conda v1.5.2, SymPy v1.0.50 and PyCall v1.92.3 were installed. However when I use the Pkg.installed() command I get:

julia> Pkg.installed()
┌ Warning: Pkg.installed() is deprecated
└ @ Pkg C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\Pkg.jl:570
Dict{String, VersionNumber} with 17 entries:
“Hwloc” => v"2.0.0"
“Distributions” => v"0.25.11"
“Atom” => v"0.12.33"
“BenchmarkTools” => v"1.1.1"
“Interpolations” => v"0.13.3"
“TimerOutputs” => v"0.5.12"
“Juno” => v"0.8.4"
“CalculusWithJulia” => v"0.0.7"
“SymPy” => v"1.0.50"
“Compat” => v"3.32.0"
“Plots” => v"1.15.2"
“GeometryBasics” => v"0.3.13"
“WebIO” => v"0.8.15"
“StaticArrays” => v"1.2.10"
“GLMakie” => v"0.4.4"
“DistributedArrays” => v"0.6.5"
“SpecialFunctions” => v"0.10.3"

This shows that SymPy got installed, but not Conda and PyCall.

If I look in “C:\Users\Richard Savage.julia\compiled\v1.6” I find a Conda folder, a PyCall folder, and a SymPy folder. And if I look in “C:\Users\Richard Savage.julia\packages” I find folders for Conda, PyCall and SymPy. Is this where you would expect to find these folders for Conda, PyCall and SymPy?

Also if I put “using Conda” in the REPL I get:
julia> using Conda
ERROR: ArgumentError: Package Conda not found in current path:

  • Run import Pkg; Pkg.add("Conda") to install the Conda package.

Stacktrace:
[1] require(into::Module, mod::Symbol)
@ Base .\loading.jl:893

Similarly if I put “using PyCall” into the REPL I get:
julia> using PyCall
ERROR: ArgumentError: Package PyCall not found in current path:

  • Run import Pkg; Pkg.add("PyCall") to install the PyCall package.

Stacktrace:
[1] require(into::Module, mod::Symbol)
@ Base .\loading.jl:893

Do you know why Julia wants me to add these packages after she said they were installed when I entered Pkg.add(“SymPy”) into the REPL?

I should also note that in my "C:" folder I have:

  1. an Anaconda2 folder which contains Python 2.7 and Python 3.5 in a TensorFlow env, and
  2. a Python37 folder that contains Python 3.7
    And, my Windows 10 environment Path is set to the following:
  3. C:\Anaconda2;C:\Anaconda2\Scripts;C:\Julia-1.6.2\bin + a few other items that are probably not relevant.
    Do you think items 1, 2 and 3 might also be causing problems adding Conda, PyCall and SymPy?

Rich

There seems to be a lot going on here, so I think it’s better to take it step by step. Before continuing, when you are working interactively in the REPL, it makes navigating this package management stuff a little easier if you use the Pkg REPL mode by pressing the ] key.
Then instead of

julia> import Pkg
julia> Pkg.add("SymPy")

you could have just done (after pressing ])

(@v1.6) pkg> add SymPy

(To get back to the usual julia> prompt, just hit Backspacke)

Not quite! First, the Pkg.installed() command is deprecated, I would recommend just using

(@v1.6) pkg> status

which should give you the same list of installed packages. Note that this will only show those packages you added directly yourself, such as SymPy. In addition, these packages will themselves depend on other packages, such as Conda and PyCall in this case. These will also be installed, but not shown by default by Pkg.status().

If you want to list not only the packages you added yourself, but also all of their dependencies, you can do (Warning: this will be a rather long list if you do it in your global v1.6 environment)

(@v1.6) pkg> status --manifest

In this list you should also find Conda and PyCall, that were automatically installed when you installed SymPy.

Although they were installed as dependencies of SymPy, if you actually want to use Conda and/or PyCall directly, you should indeed add them explicitly via pkg> add Conda and/or pkg> add PyCall as the error message in the REPL suggests. Packages usually depend on several other packages, but are generally designed in such a way that you only need to load the top-level package via using.

It is a little hard for me to say, but I think that these shouldn’t interfere when PyCall is configured using the Julia-specific Python distribution installed by Conda.jl, as you had shown above.

The good thing is, adding SymPy (the Julia package) worked, now it is just about installing SymPy (the Python module) and making PyCall aware of where it is located.
Moving forward, I would try to either

  1. Stick with the Julia-specific python distribution and try to figure out why installing sympy results in an error. As suggested above, it might be preferable if you create a fresh environment instead of using the global v1.6 one (I would really recommended reading at least through the Getting Started section of the Pkg documentation, it isn’t even that long and really helps wrapping your head around how package management works in Julia).
    Does pkg> add SymPy followed by julia> using SymPy (which should automatically install the python module sympy via conda) work then? If not, do at least other Conda commands work, such as Conda.list() or Conda.update()?
  2. Make use of your existing Anaconda installation (in C:\Anaconda2), create a new Python3 environment for julia there, install sympy in this environment (all outside of Julia) and configure PyCall to use that instead.

bvrd – Thanks again for replying to my post. All of your suggestions were excellent. I learned a lot, especially from reading the Julia Package documentation at “http://pkgdocs.julialang.org/v1/”.

I tried a lot of different things to get SymPy to work with the Julia-specific Python distribution. This is what eventually worked:

  1. Installed Python 3.9.6 in my root directory on C-drive
  2. Opened a Windows “cmd” window and used “cd” command to navigate to “C:\Python39\Scripts” scripts directory which contains “pip.exe”
  3. Installed “mpmath” using “pip install mpmath”
  4. Installed “sympy” using “pip install sympy”
  5. “mpmath” and “sympy” got installed in “C:\Python39\Lib\site-packages” in the following 4 folders:
    a) mpmath
    b) mpmath-1.2.1.dist-info
    c) sympy
    d) sympy-1.8.dist-info
  6. I made copies of items a, b, c and d and put them into the following Julia folder: “C:\Users\Richard Savage.julia\conda\3\Lib\site-packages”
  7. Opened the Julia REPL and added packages in the following order: “SymPy”, “PyCall” and “Conda”.
  8. This worked!

Thanks again for your help,
Rich

1 Like

Glad to hear you got it to work in the end!