Closed zhyiyu closed 3 years ago
This most likely means that the python module was compiled and installed in a different python environment. You can check the python version and module location in the installation output and make sure it matches your current python interpret and environment (including PYTHONPATH).
Moreover: default python
on systems used to be python2
, but most likely you want to use python3
, so you need to to fix one line in configure.ac
:
https://github.com/scarrazza/apfel/blob/df064ef35050472b39e31e9e1f0ac731defb5bdb/configure.ac#L99
adding parenthesis for the print
function (before was the print
statement), then reconfigure (to regenerate the corrected configure
script):
autoreconf -f -i
and specify it at install time
PYTHON=$(which python3) ./configure
@AleCandido Thank you for the comment, I have modified line 88 of apfel/configure.ac
such that it now looks like
python_incpath=`$PYTHON -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_inc();)"`
and run autoreconf -f -i
, which I think gave message of success (no errors). However, when I ran
PYTHON=$(which python3) ./configure --prefix=/path/to/destination
I got error
Illegal variable name.
Is there anything I did wrong?
Thanks!
By the way, when I echo $PYTHON
, I get PYTHON: Undefined variable.
.
print(distutils.sysconfig.get_python_inc();)"`
Closed parenthesis is in the wrong position:
print(distutils.sysconfig.get_python_inc());"`
By the way, when I
echo $PYTHON
, I getPYTHON: Undefined variable.
.
This is expected, when you put at the beginning of the command you only set for that one, but it does not persist in your environment.
If you want to keep it you can simply issue a command before with export PYTHON=$(which python3)
(export
is needed to make it available to subshells).
@AleCandido Thank you, I have fixed the parenthesis and defined $PYTHON
. However, after the installation, I still can not import apfel
in Python 3.
And I checked config.log
as suggested by @scarrazza, I think it is using indeed the correct Python 3 path I have
configure:20263: checking for python
configure:20293: result: /w/jam-sciwork18//zyy/packages/anaconda_3/bin/python3
Is there something else that I can check? Thanks!
Then do the thing in two steps as said before:
export PYTHON=$(which python3)
./configure
etc. (i.e. make
and make install
)At this point you can check what PYTHON3
is, by:
echo $PYTHON3
the apfel
package should then be available from that interpreter (that in the first place is the interpreter that you accessed with which python3
, and so the one you enter when you enter python3
as a command).
Actually, when you enter make install
it should copy the stuffs around, and it's printing where, e.g.:
copying build/lib.linux-x86_64-3.8/_apfel.cpython-38-x86_64-linux-gnu.so -> /home/alessandro/Projects/N3PDF/external/apfel/env/lib/python3.8/site-packages
you could then try to grep during make install
:
make install | grep "copying"
to see where the .so
has been installed.
I found out where the .so
file is moved to
copying build/lib.linux-x86_64-3.7/_apfel.cpython-37m-x86_64-linux-gnu.so -> /w/jam-sciwork18/zyy/packages/apfel/lib/python3.7/site-packages
Hence I do
import sys
sys.path.append('/w/jam-sciwork18/zyy/packages/apfel/lib/python3.7/site-packages')
import apfel
and it works! Thank you for your help! Hope this becomes easier in the future!
By the way, is it still necessary to define environmental variables PYTHON
and PYTHON3
?
By the way, is it still necessary to define environmental variables
PYTHON
andPYTHON3
?
Nope: the PYTHON
variable is only required during the run of configure
, that's why the first time I told you to put it inline. Later on I told you to export only for debug purpose.
PYTHON3
variable should be completely unused, so it's useless to define it (and maybe confusing).
and it works! Thank you for your help! Hope this becomes easier in the future!
I agree that it's not as easy as pip install apfel
, but should not even be that complicated: somehow you are installing in:
/w/jam-sciwork18/zyy/packages/apfel/
this is the prefix that is determined, and there will be most likely a python executable there, but instead you are using another one, i.e.:
/w/jam-sciwork18//zyy/packages/anaconda_3/bin/python3
So:
/w/jam-sciwork18/zyy/packages/apfel/bin/python
(or /w/jam-sciwork18/zyy/packages/apfel/bin/python3
/w/jam-sciwork18/zyy/packages/apfel/bin/python3.7
) as a command, then you should be able there to directly import apfel
, without the need of changing your pathPYTHON
during configure
, and changing prefix, so running:
PYTHON=/w/jam-sciwork18//zyy/packages/anaconda_3/bin/python3 ./configure --prefix=/w/jam-sciwork18//zyy/packages/anaconda_3/
Moreover consider that:
I see, so by
if you want to use it from your anaconda environment you should be able to install there, specifying that one as
PYTHON
duringconfigure
, and changing prefix, so running:
actually you mean that APFEL
is supposed to be installed within anaconda
if I would like to import it from Python. But maybe I should put it within
/w/jam-sciwork18//zyy/packages/anaconda_3/pkgs/
I installed APFEL and tried to use it in Python
and see the following error
However, import in C++ has no issues
Could you please point out to me what I should do to make APFEL importable in Python? Thanks!