PythonOCC Basic example not working - python

Using the basic example on their website:
from OCC.Display.SimpleGui import init_display
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
display, start_display, add_menu, add_function_to_menu = init_display()
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
display.DisplayShape(my_box, update=True)
start_display()
I can't get that to run? Any ideas?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\site-packages\OCC\Display\SimpleGui.py", line 164, in init_display
win.canva.InitDriver()
File "C:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\site-packages\OCC\Display\pysideDisplay.py", line 79, in InitDriver
self._display = OCCViewer.Viewer3d(self.GetHandle())
File "C:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\site-packages\OCC\Display\pysideDisplay.py", line 55, in GetHandle
return int(self.winId())
TypeError: int() argument must be a string or a number, not 'PyCObject'

That's a duplication of a github issue:
https://github.com/tpaviot/pythonocc-core/issues/68
we need to know which GUI library your using and what verion of pythonocc you are one.
this is an older version of pythonocc, the current you can find here:
Why not try and install that newer version?
Its important that the OCE library you've got installed match.
So pythonocc-core 0.16 goes with OCE 0.16

Related

(Python) ColabTurtle requires has initializeturtle() error, but we already used it

code:
import ColabTurtle.Turtle as tutel
tutel.initializeTurtle()
tutel.forward(10)
error is:
<IPython.core.display.HTML object>
Traceback (most recent call last):
File "f:\stuff\e.py", line 3, in <module>
tutel.forward(10)
File "C:\Users\U.S.E.R\AppData\Local\Programs\Python\Python311\Lib\site-packages\ColabTurtle\Turtle.py", line 174, in forward
_moveToNewPosition(ending_point)
File "C:\Users\U.S.E.R\AppData\Local\Programs\Python\Python311\Lib\site-packages\ColabTurtle\Turtle.py", line 163, in _moveToNewPosition
_updateDrawing()
File "C:\Users\U.S.E.R\AppData\Local\Programs\Python\Python311\Lib\site-packages\ColabTurtle\Turtle.py", line 144, in _updateDrawing
raise AttributeError("Display has not been initialized yet. Call initializeTurtle() before using.")
AttributeError: Display has not been initialized yet. Call initializeTurtle() before using.
basically, it tells me to use intializeturtle() before running a ColabTurtle function. Except, i did already use it.
Help.
Try to run it in Google Collab. If there will be no module ColabTurtle, you need to create a new code (+code) and write
!pip install ColabTurtle

Chatterbot installation working, but broken calls to variables

I installed chatterbot in my terminal earlier today using virtual studio code's terminal. I saw that both chatterbot and chatterbot_corpus worked in installation. Then, I made the following python document:
EDIT: Turns out I should define a chatbot variable first.
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
bot = ChatBot('Maya')
trainer = ListTrainer(bot)
trainer.train(conversation)
This was my code
it says this however
bot = ChatBot('Maya')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
Does anyone know how to fix this easily?
EDIT: I just updated python using pip install --upgrade ipython in terminal, but it didn't fix the issue
EDIT 2: Well now I tried updating a package using pip install sqlalchemy --upgrade
But now it gives
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
if not self.engine.dialect.has_table(self.engine, 'Statement'):
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
self._ensure_has_table_connection(connection)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>,
got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
I am in the latest version though
PS C:\Users\Subha> Python --version
Python 3.9.6
EDIT 3: Now it comes up with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
# if not self.engine.dialect.has_table(self.engine, 'Statement'):
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
self._ensure_has_table_connection(connection)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>, got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
it seems the python upgrade worked with regard to the initial error on time.clock. This new error you are seeing is quite different to the previous one. In this case you need to go into chatterbot/storage/sql_storage.py and comment out if not self.engine.dialect.has_table(self.engine, 'Statement'): and leave only self.create_database(). This means that instead of checking whether a database table has been created which is triggering the error, it will just create the DB every time, which i expect to work fine.
# if not self.engine.dialect.has_table(self.engine, 'Statement'):
self.create_database()

Did pyglet change recently?

So, The other day, I went back to an old project to finish it but when I tried running it, it gave me several errors that I've tried to fix but some of them I don't know how to fix. The program worked fine when I stopped working on it, so I'm very confused at what happened. My guess is that pyglet got a new update and removed a lot of stuff I used to use. Some of the errors I get are as follows
Traceback (most recent call last):
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 9,
in <module>
screen =
pyglet.window.get_platform().get_default_display().get_default_screen()
AttributeError: module 'pyglet.window' has no attribute 'get_platform'
and
Traceback (most recent call last):
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 216, in <module>
main()
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 208, in main
win = Window(caption = "3D Program 1", width = WINW, height = WINH, resizable = False, vsync = True)
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 57, in __init__
self.tex1 = get_tex("steel_tex.png")
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 21, in get_tex
tex = pyglet.image.load(file).texture
AttributeError: 'ImageData' object has no attribute 'texture'
I also had problems with it saying that there was no such thing as the "pyglet.graphics.TextureGroup" class
Yes, it looks like both of snippets of code you show are using features that were deprecated in previous versions of Pyglet and removed in the recent 1.4 release. You can see the deprecation (and their suggested replacements) in the documentation for older versions:
The get_platform() function in pyglet.window:
Deprecated. Use pyglet.canvas.Display.
The .texture attribute of an image:
Deprecated. Use get_texture().

python3 ImportError: cannot import name 'rand_str'

Im getting this error when starting my software i dont know how to repair this
Traceback (most recent call last):
File "/root/findex/lib/python3.5/site-packages/findex_gui/main.py", line 208, in web
run_async()
File "/root/findex/lib/python3.5/site-packages/findex_gui/main.py", line 201, in run_async
from findex_gui.web import app
File "/root/findex/lib/python3.5/site-packages/findex_gui/web.py", line 41, in <module>
from findex_gui.orm.connect import Database
File "/root/findex/lib/python3.5/site-packages/findex_gui/orm/connect.py", line 12, in <module>
from findex_gui.orm.models import BASE
File "/root/findex/lib/python3.5/site-packages/findex_gui/orm/models.py", line 22, in <module>
from findex_common.utils import rand_str
ImportError: cannot import name 'rand_str'
I'm not familiar with the libraries in question, but it seems the maintainer renamed this function in 0.15.14 of findex-common here: development
This has been adjusted for in findex-gui on the master branch though it seems it has not seen a release. Here's the commit which fixes the import: Forgot what I was doing - Ill just push it all ¯_(ツ)_/¯
One short term fix would be to downgrade to findex-common==0.15.13 and perhaps follow up by raising an issue on either project since the change seems non-ideal.

Python Cant Run or Reinstall Pip

I have a machine that has Python 2.7 and Python 3.4 installed. Normally to install packages under Python 3.4, I would run pip3 install [PACKAGE].
But now when I run pip3 I get
Traceback (most recent call last):
File "/volume1/#appstore/python3/bin/pip3", line 7, in <module>
from pip import main
File "/usr/local/python3/lib/python3.4/site-packages/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/python3/lib/python3.4/site-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/usr/local/python3/lib/python3.4/site-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
File "/usr/local/python3/lib/python3.4/site-packages/pip/wheel.py", line 32, in <module>
from pip import pep425tags
File "/usr/local/python3/lib/python3.4/site-packages/pip/pep425tags.py", line 335, in <module>
supported_tags = get_supported()
File "/usr/local/python3/lib/python3.4/site-packages/pip/pep425tags.py", line 307, in get_supported
elif is_manylinux1_compatible():
File "/usr/local/python3/lib/python3.4/site-packages/pip/pep425tags.py", line 163, in is_manylinux1_compatible
return have_compatible_glibc(2, 5)
File "/usr/local/python3/lib/python3.4/site-packages/pip/pep425tags.py", line 187, in have_compatible_glibc
version = [int(piece) for piece in version_str.split(".")]
File "/usr/local/python3/lib/python3.4/site-packages/pip/pep425tags.py", line 187, in <listcomp>
version = [int(piece) for piece in version_str.split(".")]
ValueError: invalid literal for int() with base 10: '20-2014'
Even if I download get-pip.py and run python3 get-pip.py, I get the same error.
What could the problem be?
Edit: Apparently this is a problem that is persistent on Synology installs when you installed DSM 6.0.
Found solution courtesy of #Tadhg in the comments above.
Here is a link to the necessary changes to pep425tags.py.
But here are the changes needed for all of you who are on this SO page.
Add the following function:
# Separated out from have_compatible_glibc for easier unit testing
def check_glibc_version(version_str, needed_major, needed_minor):
# Parse string and check against requested version.
#
# We use a regexp instead of str.split because we want to discard any
# random junk that might come after the minor version -- this might happen
# in patched/forked versions of glibc (e.g. Linaro's version of glibc
# uses version strings like "2.20-2014.11"). See gh-3588.
m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str)
if not m:
warnings.warn("Expected glibc version with 2 components major.minor,"
" got: %s" % version_str, RuntimeWarning)
return False
return (int(m.group("major")) == needed_major and
int(m.group("minor")) >= needed_minor)
and replace
# Parse string and check against requested version.
version = [int(piece) for piece in version_str.split(".")]
if len(version) < 2:
warnings.warn("Expected glibc version with 2 components major.minor,"
" got: %s" % version_str, RuntimeWarning)
return False
return version[0] == major and version[1] >= minimum_minor
with return check_glibc_version(version_str, major, minimum_minor)

Categories

Resources