I have coded a mathematical model and want to solve it using DOCPLEX module. My interpreter is Python 3.7. However, after doing a lot of effort, I will face the following error:
Traceback (most recent call last):
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 290, in get_cplex_module
import cplex ##UnresolvedImport
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\__init__.py", line 44, in <module>
from .aborter import Aborter
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\aborter.py", line 13, in <module>
from ._internal import _procedural as _proc
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\__init__.py", line 20, in <module>
from . import _list_array_utils
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\_list_array_utils.py", line 14, in <module>
from . import _pycplex as CPX
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\_pycplex.py", line 13, in <module>
from . import _pycplex_platform
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\_pycplex_platform.py", line 22, in <module>
from cplex._internal.py37_cplex2010 import *
ModuleNotFoundError: No module named 'cplex._internal.py37_cplex2010'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/pythonProject/EPC _LTC.py", line 11, in <module>
mdl = Model("LTC")
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\model.py", line 398, in __init__
self._environment = self._make_environment()
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\model.py", line 174, in _make_environment
env = Environment.get_default_env()
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 427, in get_default_env
Environment._default_env = Environment.make_new_configured_env()
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 422, in make_new_configured_env
return Environment(start_auto_configure=True)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 84, in __init__
self.auto_configure(logger=logger)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 220, in auto_configure
self.check_cplex(logger=logger)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 328, in check_cplex
cplex = self.get_cplex_module(logger=logger)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 314, in get_cplex_module
cplex = load_cplex_from_cos_root(loc) if loc else None
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 286, in load_cplex_from_cos_root
return load_cplex(full_path, version=version)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 261, in load_cplex
raise FileNotFoundError("Could not load module from %s" % module_location)
FileNotFoundError: Could not load module from C:\Program Files\IBM\ILOG\CPLEX_Studio201;C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64;C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64\cplex;\cplex\python\3.7\x64_win64\cplex\__init__.py
I have already run the following codes in my Pycharm's terminal:
cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python
python setup.py install
or
cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python
python setup.py install --home C:\Users\xxx\PycharmProjects\pythonProject\venv\Lib\site-packages\cplex
Finally, I also set the path variables of my own username to something like below:
"C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\python\3.6\x64_win64" and
"C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\bin\x64_win64\cplex.exe"
In my case I upgraded to python 3.8 and solved the issue
or you can use this:
pip install docplex==2.15.194
The problem is that python setup.py install does not guaranty that the python interpreter you are using is the same as your virtual env.
You need to activate your env before you run the install script.
Please open a Terminal then run:
C:\Users\xxx\PycharmProjects\pythonProject\venv\Scripts\activate
Then you can
cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python
pip install .
Docplex has a check_list.py script, which helps diagnose presence and location of cplex versions. In a terminal where Python is present, type
$ python -m docplex.mp.check_list
The answer looks like:
* system is: Windows 64bit
* Python version 3.7.8, located at: C:\python\anaconda2020.02\envs\docplex37\python.exe
* docplex is present, version is 2.20.204
* CPLEX library is present, version is 12.10.0.0, located at: C:\OPTIM\cplex_distrib\cplex1210R0\python\3.7\x64_win64
* pandas is present, version is 1.1.4
From the check list output you posted, I can see that you installed cos201.
Docplex need the Python/Cplex interface located inside cos, in your case:
C:/Program Files/IBM/ILOG/CPLEX_Studio201/cplex/python/3.7/x64_win64
This path should be added as a content root in your Pycharm project (File/Settings/Project Structure -> add content root
To check this, open a Python console tab in Pycharm, and try
import cplex
Once you add the right path , this should work.
You can then run the check list from within the console:
from docplex.mp.check_list import run_docplex_check_list
run_docplex_check_list()
Once this works, your program should solve OK inside Pycharm.
This said, I see your version of docplex is 2.15, which is older than CPLEX 20.1. You should update DOcplex to the latest version, which is compatible with CPLEX 20.1.
Related
I am aware of this similar question, but that is on Windows and not for Mac M1, and their solution didn't work for me.
Aim
I would like to be able to use the python package oct2py.
Set Up and Problem
I have a new Mac M1. I have installed Anaconda using the 64-Bit (M1) Graphical Installer (316 MB). I have created an environment env-name, activated it, and installed oct2py using the command conda install -c conda-forge oct2py. In Python, when running from oct2py import octave or simply import oct2py it fails with the following traceback
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/anaconda3/envs/env-name/lib/python3.10/site-packages/oct2py/__init__.py", line 38, in <module>
octave = Oct2Py()
File "/opt/anaconda3/envs/env-name/lib/python3.10/site-packages/oct2py/core.py", line 83, in __init__
self.restart()
File "/opt/anaconda3/envs/env-name/lib/python3.10/site-packages/oct2py/core.py", line 533, in restart
self._engine = OctaveEngine(stdin_handler=self._handle_stdin,
File "/opt/anaconda3/envs/env-name/lib/python3.10/site-packages/octave_kernel/kernel.py", line 173, in __init__
self.executable = self._get_executable()
File "/opt/anaconda3/envs/env-name/lib/python3.10/site-packages/octave_kernel/kernel.py", line 472, in _get_executable
raise OSError('octave not found, please see README')
OSError: octave not found, please see README
all,
I've installed the package:pywinauto successfully with "pip install pywinauto", but it always fails, why?
I did it in this way:
pip install pywinauto
and then under the windows cmd env, I run the python:
and then:
import pywinauto
I got the following errors:
....
>>> import pywinauto
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pywinauto\__init__.py", line 40, in <module>
from . import findwindows
File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Python27\lib\site-packages\pywinauto\controls\__init__.py", line 36,in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Python27\lib\site-packages\pywinauto\controls\uiawrapper.py", line 44, in <module>
from ..uia_defines import IUIA
File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 175, in <module>
pattern_ids = _build_pattern_ids_dic()
File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 163, in _build_pattern_ids_dic
if hasattr(IUIA().ui_automation_client, cls_name):
File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 60, in __init__
self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
File "C:\Python27\lib\site-packages\comtypes\client\_generate.py", line 97, in GetModule
tlib = comtypes.typeinfo.LoadTypeLibEx(tlib)
File "C:\Python27\lib\site-packages\comtypes\typeinfo.py", line 485, in LoadTypeLibEx
_oleaut32.LoadTypeLibEx(c_wchar_p(szFile), regkind, byref(ptl))
File "_ctypes/callproc.c", line 950, in GetResult
WindowsError: [Error -2147312566] Error loading type library/DLL
It looks like you're using old OS Windows version like Windows XP. MS UI Automation is included into Windows Vista and later. But you may install .NET Framework 3.0+ to get UIAutomationCore.dll available even on Windows XP. If you don't need MS UI Automation technology at all, just run pip uninstall comtypes and pywinauto will work with Win32 API only.
If installing .NET Framework 3.0+ doesn't help (or if it's already installed) and you need to use Win XP, install Windows update KB971513. It solved the loading library issue for me.
I need upgrade the Winxp to Win7 or Win8, or Win10.
I was trying to use virtualenv to switch between python versions before learning that I could use both python and python3 on my Mac.
I was able to fix my python 2.7 version so that still works fine however, now when I run python3, I get this error:
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 125, in <module>
import functools
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I've looked online for this error but most of the conversation was on fixing up the patch and then upgrading virtualenv. However, this still doesn't fix my issue.
python3 -V: Python 3.6.0
virtualenv --version: 15.1.0
env | egrep -i 'python|virtualenv': PYTHONPATH=/usr/local/lib/python2.7/site-packages:
Your environment contains PYTHONPATH=/usr/local/lib/python2.7/site-packages
This doesn't work with Python 3 for obvious reasons. To remove it:
unset PYTHONPATH
I solved my problem with below command
sudo pip install virtualenv --upgrade
virtualenv -p python3 env
I'm attempting to install pip for arcpy (arcgis 10.2 on windows 7). Running get-pip.py results in the following error message:
X:\python>python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "c:\temp\tmpou5fje\pip.zip\pip\__init__.py", line 26, in <module>
File "c:\temp\tmpou5fje\pip.zip\pip\utils\__init__.py", line 27, in <module>
File "c:\temp\tmpou5fje\pip.zip\pip\_vendor\pkg_resources\__init__.py", line 73, in <module>
File "c:\temp\tmpou5fje\pip.zip\pip\_vendor\packaging\specifiers.py", line 275, in <module>
File "c:\temp\tmpou5fje\pip.zip\pip\_vendor\packaging\specifiers.py", line 373, in Specifier
File "C:\Python27\ArcGIS10.2\Lib\re.py", line 190, in compile
return _compile(pattern, flags)
File "C:\Python27\ArcGIS10.2\Lib\re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
Using an administrator command prompt doesn't help. My real goal is to get win32com working under arcpy. I usual just copy the appropriate directories out of c:\python27\lib\site-packages to c:\python27\arcgis10.2\lib\site-packages to install a package under arcpy (why doesn't arcpy come with pip?) but that's not working for win32com, presumably do to a missing dll or other windows specific file.
I would recommend the following:
Get the setuptools module
Get the pip module`
And then run the following in command line (assuming windows)
path-to-python path-to-setuptools install
path-to-python path-to-pip install
I work on a closed network (away from the interwebs of old) and cannot use get-pip.py so I find it best to simply download the actual modules and hard install.
Keep us posted!
Copy get_pip.py to "C:\Python27\ArcGIS10.2", then perform command "python get-pip.py" in the directory.
Note that keep network connected in the process, so that auto-download and setup setuptools,wheels,etc.
Hope that can help you.
Try opening a CMD prompt and typing:
C:\Python27\ArcGIS10.2\python.exe -m pip install -U pip
Twisted located at C:\Python26\Lib\site-packages\Twisted-11.0.0-py2.6-win32.egg\twisted
but
C:\projects\webmorda>twistd -n morda_server
Traceback (most recent call last):
File "C:\Python26\Scripts\twistd.py", line 4, in <module>
import pkg_resources
File "C:\Python27\lib\site-packages\pkg_resources.py", line 2671, in <module>
working_set.require(__requires__)
File "C:\Python27\lib\site-packages\pkg_resources.py", line 654, in require
needed = self.resolve(parse_requirements(requirements))
File "C:\Python27\lib\site-packages\pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: twisted==11.0.0
what's wrong?
It looks like you have installed Twisted in a Python 2.6 environment but are using Python 2.7 to run it. I think the following command should work:
C:\Python26\python.exe C:\Python26\Scripts\twistd.py -n morda_server
(It looks like the twistd.py script is being run by the python.exe binary associated with the .py file extension - which in your case appears to be Python 2.7. Alternatively you have a PYTHONPATH environment variable set up to point to the Python 2.7 site-packages directory.)