Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import python file #681

Closed
YP-Ye opened this issue Apr 23, 2019 · 1 comment
Closed

cannot import python file #681

YP-Ye opened this issue Apr 23, 2019 · 1 comment

Comments

@YP-Ye
Copy link

YP-Ye commented Apr 23, 2019

I used to import local python modules successfully but I fail it today. Here is my test example to import testing.py.

using PyCall
pushfirst!(PyVector(pyimport("sys")."path"), "")
@pyimport testing

It shows the following errors:

PyError (PyImport_ImportModule

The Python package testing could not be found by pyimport. Usually this means
that you did not install testing in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:

C:\Anaconda3\python.exe

and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the testing module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia.  As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the testing module, you can use `pyimport_conda("testing", PKG)`,
where PKG is the Anaconda package the contains the module testing,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'testing'",)

pyimport(::String) at PyCall.jl:544
top-level scope at PyCall.jl:588

Any suggestion to solve it?

@YP-Ye
Copy link
Author

YP-Ye commented Apr 23, 2019

run pushfirst!(PyVector(pyimport("sys")."path"), @__DIR__) can solve it.

@YP-Ye YP-Ye closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant