SystemsBioinformatics / cbmpy

CBMPy is a Python based platform for constraint based modelling and analysis.
https://systemsbioinformatics.github.io/cbmpy/
GNU General Public License v3.0
19 stars 6 forks source link

Issue installing in python3 does not handle the ancillary xml files correctly if pyhton 2.7 is defaut #14

Closed mabawsa closed 5 years ago

mabawsa commented 5 years ago

OS: ubuntu 18.04 CBMPy (0.7.21) scenario: installing using pip3 on a python 2.7 default system. I require both to refactor code.

Python 2.7 works just fine, but when I try installing in Python 3, cbmpy comes up with the following error:

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cbmpy

INFO: No xlwt module available, Excel spreadsheet creation disabled
GLPK not available

*****
Using CPLEX
*****

Installing default models ...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/cbmpy/__init__.py", line 61, in <module>
    from .CBRead import loadModel, readSBML3FBC, readSBML2FBA, readCOBRASBML
  File "/usr/local/lib/python3.6/dist-packages/cbmpy/CBRead.py", line 90, in <module>
    zfile.extractall(path=__example_model_path__)
  File "/usr/lib/python3.6/zipfile.py", line 1524, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "/usr/lib/python3.6/zipfile.py", line 1578, in _extract_member
    open(targetpath, "wb") as target:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/cbmpy/models/core_memesa_model.l3.xml'

seems a file may be missing:

ls /usr/local/lib/python3.6/dist-packages/cbmpy/models/
default_models.zip.py
ls /usr/local/lib/python2.7/dist-packages/cbmpy/models/
core_memesa_model.l3.xml  default_models.zip.py  Ecoli_iJR904.glc.l3.xml

when I link the xml files I then get:

Installing test files (v1)...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/cbmpy/__init__.py", line 105, in <module>
    zfile.extractall(path=__test_dir__)
  File "/usr/lib/python3.6/zipfile.py", line 1524, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "/usr/lib/python3.6/zipfile.py", line 1578, in _extract_member
    open(targetpath, "wb") as target:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/cbmpy/nosetests/data.json'

In summary I needed to do the following to resolve this:

sudo cp /usr/local/lib/python2.7/dist-packages/cbmpy/models/*.xml /usr/local/lib/python3.6/dist-packages/cbmpy/models/
sudo cp /usr/local/lib/python2.7/dist-packages/cbmpy/nosetests/*.xml /usr/local/lib/python3.6/dist-packages/cbmpy/nosetests/
sudo cp /usr/local/lib/python2.7/dist-packages/cbmpy/nosetests/*.json /usr/local/lib/python3.6/dist-packages/cbmpy/nosetests/
sudo cp /usr/local/lib/python2.7/dist-packages/cbmpy/nosetests/installed.v1 /usr/local/lib/python3.6/dist-packages/cbmpy/nosetests/
bgoli commented 5 years ago

Thanks for the detailed report. This is a permissions issue with the built in testsuite, that I am currently looking into improving.

bgoli commented 5 years ago

Just an update the testsuite code has been moved out of the source into it's own branch and the example models are now stored as Python strings. Implemented in trunk, needs some multios testing.

mabawsa commented 5 years ago

Just tried to install on a new machine and it seems even python 2.7 has regressed:

dougie@celldynamics:~$ sudo -H python2 -m pip install --upgrade cbmpy
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already up-to-date: cbmpy in /usr/local/lib/python2.7/dist-packages (0.7.21)
dougie@celldynamics:~$ python2
Python 2.7.15+ (default, Nov 27 2018, 23:36:35) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cbmpy
WARNING: SBML support not available, please install libSBML, Python bindings with FBC (sbml.org)
INFO: SBML+GROUPS support not available, update to latest version of libSBML if required
GLPK not available

No module named cplex

CPLEX not available

*****
WARNING: No linear solver present, please install IBM CPLEX with Python bindings or PyGLPK, please see http://cbmpy.sourceforge.net for Windows binary or http://tfinley.net/software/pyglpk for source.
*****

No solver present, unable to create shortcuts

WARNING: No SBML support, top-level SBML read/write functions disabled.

Installing default models ...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/cbmpy/__init__.py", line 91, in <module>
    from . import CBModel, CBDataStruct, CBModelTools, CBRead, CBReadtxt, CBTools, CBWrite, CBXML, CBNetDB, CBPlot, CBMultiModel
  File "/usr/local/lib/python2.7/dist-packages/cbmpy/CBRead.py", line 90, in <module>
    zfile.extractall(path=__example_model_path__)
  File "/usr/lib/python2.7/zipfile.py", line 1063, in extractall
    self.extract(zipinfo, path, pwd)
  File "/usr/lib/python2.7/zipfile.py", line 1051, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/lib/python2.7/zipfile.py", line 1106, in _extract_member
    file(targetpath, "wb") as target:
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/cbmpy/models/core_memesa_model.l3.xml'
>>> 

and python 3:

dougie@celldynamics:~$ sudo -H python3 -m pip install --upgrade cbmpy
Requirement already up-to-date: cbmpy in /usr/local/lib/python3.6/dist-packages (0.7.21)
dougie@celldynamics:~$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cbmpy

INFO: No xlwt module available, Excel spreadsheet creation disabled
GLPK not available

*****
Using CPLEX
*****

Installing default models ...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/cbmpy/__init__.py", line 61, in <module>
    from .CBRead import loadModel, readSBML3FBC, readSBML2FBA, readCOBRASBML
  File "/usr/local/lib/python3.6/dist-packages/cbmpy/CBRead.py", line 90, in <module>
    zfile.extractall(path=__example_model_path__)
  File "/usr/lib/python3.6/zipfile.py", line 1524, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "/usr/lib/python3.6/zipfile.py", line 1578, in _extract_member
    open(targetpath, "wb") as target:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/cbmpy/models/core_memesa_model.l3.xml'
>>> 

Everything works OK if I copy over the contents of \models\ and \nosetests\ from another machine with the old installation.

bgoli commented 5 years ago

Hi, it's taking a while to for me to wrap up a new release (hopefully as soon as next week) but I've fixed this problem so that CBMPy no longer creates temporary files. Right now you need to clone the source repository and run sudo python setup.py install to install the latest code.

The Python 2.7 warning is from pip and can be ignored.

bgoli commented 5 years ago

This has been fixes in the 0.7.25 release now available from PyPI Conda etc