I have Python 2 and Python 3 installed on my system.
I run the following script:
#!/usr/bin/env python
import nxt.locator
from nxt.motor import *
def spin_around(b):
m_left = Motor(b, PORT_B)
m_left.turn(100, 360)
m_right = Motor(b, PORT_C)
m_right.turn(-100, 360)
b = nxt.locator.find_one_brick()
spin_around(b)
with the command: python spin.py which uses Python 2, as expected.
However, when I run this command I get the following error:
Traceback (most recent call last):
File "spin.py", line 12, in <module>
b = nxt.locator.find_one_brick()
File "/Library/Python/2.7/site-packages/nxt/locator.py", line 112, in find_one_brick
for s in find_bricks(host, name, silent, method):
File "/Library/Python/2.7/site-packages/nxt/locator.py", line 43, in find_bricks
for s in socks:
File "/Library/Python/2.7/site-packages/nxt/usbsock.py", line 84, in find_bricks
for bus in usb.busses():
File "/Library/Python/2.7/site-packages/usb/legacy.py", line 353, in busses
sorted(core.find(find_all=True), key=lambda d: d.bus),
File "/Library/Python/2.7/site-packages/usb/core.py", line 1263, in find
raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available
When I run this script my NXT is plugged into my computer by USB and my NXT is on. Additionally, I have installed pyUSB (correctly, I think).
Why could this error be occurring?
The solution was to install libUSB. It seems the pyUSB library relies on libUSB in the background.
I installed libUSB with brew install libusb
Afterwards, that particular error was fixed.
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
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.
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 am trying to run PyCallgraph module on my application. My application runs on Mac and I am running the application from PyCharm
Here is what I have tried
def main(url):
from pycallgraph import PyCallGraph
from pycallgraph.output import GephiOutput, GraphvizOutput
graphviz = GraphvizOutput()
with PyCallGraph(output=graphviz):
obj = MyApp("agr1")
obj.extract('372','100001' , '999')
I am getting the following error ...
libpath/shortest.c:324: triangulation failed
libpath/shortest.c:192: source point not in any triangle
Error: in routesplines, Pshortestpath failed
Traceback (most recent call last):
File "/Users/anurag/Work/quad-projects/quad-hge/src/main/python/extractor/hgextractor.py", line 63, in <module>
main(url)
File "/Users/anurag/Work/quad-projects/quad-hge/src/main/python/extractor/hgextractor.py", line 51, in main
hge.extract('372','100001' , '999', url_list)
File "/Users/anurag/.virtualenvs/robot/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 38, in __exit__
self.done()
File "/Users/anurag/.virtualenvs/robot/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 81, in done
self.stop()
File "/Users/anurag/.virtualenvs/robot/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 90, in generate
output.done()
File "/Users/anurag/.virtualenvs/robot/lib/python2.7/site-packages/pycallgraph/output/graphviz.py", line 112, in done
'code %(ret)i.' % locals())
pycallgraph.exceptions.PyCallGraphException: The command "dot -Tpng -opycallgraph.png /var/folders/00/z1t7sw2x1ml1ydhgp084c1xh0000gn/T/tmphl_rNH" failed with error code 11.
Process finished with exit code 1
I even tried installing graphviz on my Mac using brew install graphviz
and setting $PATH variable on my PyCharm editor as described here pycallgraph with pycharm does not work
I don't know the exact root cause for this and I am stuck at this for last 2-3 days.
Since my laptop crashed (for unknown reason) last night, Spyder has not been able to connect to a kernel. I am getting this error:
IOError: Could not find u'kernel-1809.json' in ['.', '~/Library/Jupyter/runtime']
(The name of the json file changes each time I attempt to launch an iPython console.)
This does not seem to be related to the matplotlib 1.5 issue, that I have seen elsewhere on here - it is using 1.4.3.
iPython (version 4.0.0) runs fine from the command line.
Mac 10.10.1 (Yosemite). Spyder 2.3.7. Python 2.7.10 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.3 on Darwin
UPDATED TO INCLUDE LOGS
>>> /Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/nbformat/current.py:19: UserWarning: nbformat.current is deprecated.
- use nbformat for read/write/validate public API
- use nbformat.vX directly to composing notebooks of a particular version
ERROR: 3rd party plugin import failed for `p_pylint`
Traceback (most recent call last):
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/otherplugins.py", line 53, in get_spyderplugins_mods
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderplugins/p_pylint.py", line 23, in <module>
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderplugins/widgets/pylintgui.py", line 71, in <module>
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderplugins/widgets/pylintgui.py", line 61, in get_pylint_version
File "subprocess.pyc", line 710, in __init__
File "subprocess.pyc", line 1335, in _execute_child
OSError: [Errno 2] No such file or directory
Traceback (most recent call last):
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/plugins/externalconsole.py", line 925, in <lambda>
give_focus=give_ipyclient_focus))
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/plugins/externalconsole.py", line 1033, in register_ipyclient
give_focus=give_focus)
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/plugins/ipythonconsole.py", line 836, in register_client
self.connect_client_to_kernel(client)
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/plugins/ipythonconsole.py", line 1048, in connect_client_to_kernel
client.password)
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/plugins/ipythonconsole.py", line 1017, in create_kernel_manager_and_client
cf = find_connection_file(connection_file)
File "/Volumes/Spyder-Py2/Spyder-Py2.app/Contents/Resources/lib/python2.7/jupyter_client/connect.py", line 185, in find_connection_file
raise IOError("Could not find %r in %r" % (filename, path))
IOError: Could not find u'kernel-2018.json' in ['.', u'/Users/garyspatterson/Library/Jupyter/runtime']
** Further update **
I deleted all files under the .spyder2/ folder in my user directory, reopened Spyder, and it was able to connect to an iPython console. So far, so good. Trouble is, when I added a path to the PYTHONPATH manager (so I could import external modules, such as nltk), I am back to getting the same error.
Had a similar issue and was able to resolve it by creating a new virtualenv with the same dependencies installed.
Now Spyder is working with the PYTHONPATH pointing at lib/python2.7/site-packages of the new environment.