I have three.js installed in my Create React App project as:
"three": "^0.115.0",
When I try to import it in component by doing:
import * as THREE from "three"; then I get (abridged):
TypeError: attribute.onUploadCallback is not a function
createBuffer
node_modules/three/build/three.module.js:14471
14468 | gl.bindBuffer( bufferType, buffer );
14469 | gl.bufferData( bufferType, array, usage );
14470 |
> 14471 | attribute.onUploadCallback();
| ^ 14472 |
14473 | var type = 5126;
If I create a file such as:
import * as THREE from "three";
window.THREE = THREE;
export default window.THREE;
then I am able to successfully import from there.
I have no idea why I need to add it to window for it to work.
The error actually had to do with a related library that uses three.js called AMI.js.
Related
After testing the logger library locally, I uploaded it to pypi.
Afterwards, when I proceeded with pip install, there was an error saying that the module inside the library could not be found.
So, as a temporary measure, I added a syntax to register all .py in init.py in the library package folder, and I want to improve this. This is because you have to install all dependencies for features that users may not be using
What improvements can I take in this situation?
If possible, I would like to know how to lazy use only the modules used by the user instead of registering all .py in init.py .
Or is there something structurally I'm overlooking?
Here is the project structure I used
project_name
- pacakge_name
- __init__.py. <- all loggers were registered
- file_logger.py
- console_logger.py
- ...
- fluent_logger.py <- used external library
- scribe_logger.py <- used external library
init.py
"""
Description for Package
"""
from .composite_logger import CompositeLogger
from .console_logger import ConsoleLogger
from .file_logger import FileLogger
from .fluent_logger import FluentLogger
from .jandi_logger import JandiLogger
from .line_logger import LineLogger
from .logger_impl import LoggerImpl
from .logger_interface import LoggerInterface
from .logger import Logger
from .memory_logger import MemoryLogger
from .null_logger import NullLogger
from .scribe_logger import ScribeLogger
from .telegram_logger import TelegramLogger
from .retry import Retry
__all__ = [
'CompositeLogger',
'ConsoleLogger',
'FileLogger',
'FluentLogger',
'JandiLogger',
'LineLogger',
'LoggerImpl',
'LoggerInterface',
'Logger',
'MemoryLogger',
'NullLogger',
'ScribeLogger',
'TelegramLogger',
'Retry',
]
setup.py
import setuptools
from distutils.core import setup
with open("README.md", "r", encoding="utf-8") as f:
long_descriprion = f.read()
setuptools.setup(
name = 'project_name',
version = '0.0.1',
description = 'python logger libary',
long_description = long_descriprion,
long_description_content_type = "text/markdown",
author = 'abc',
author_email = 'abc#gmail.com',
url = "https://github.com/##/##",
packages = ["pacakge_name"],
install_requires=[ <- contains too many external libraries
'requests>=2.0.0',
'thrift>=0.16.0',
'facebook-scribe>=2.0.post1',
'fluent-logger>=0.10.0'
],
keywords = ['logger'],
python_requires = '>=3.7',
classifiers = [
'Programming Language :: Python :: 3.7',
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
],
)
when i use the st.cache decorator to cash hugging-face transformer model i get
Unhashable TypeError
this is the code
from transformers import pipeline
import streamlit as st
from io import StringIO
#st.cache(hash_funcs={StringIO: StringIO.getvalue})
def model() :
return pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
after searching in issues section in streamlit repo
i found that hashing argument is not required , just need to pass this argument
allow_output_mutation = True
This worked for me:
from transformers import pipeline
import tokenizers
import streamlit as st
import copy
#st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None})
def get_model() :
return pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
input = st.text_input('Text')
bt = st.button("Get Sentiment Analysis")
if bt and input:
model = copy.deepcopy(get_model())
st.write(model(input))
Note 1:
calling the pipeline with input model(input) changes the model and we shouldn't change a cached value so we need to copy the model and run it on the copy.
Note 2:
First run will load the model using the get_model function next run will use the chace.
Note 3:
You can read more about Advanced caching in stremlit in thier documentation.
Output examples:
This question already has answers here:
Uncaught SyntaxError: Cannot use import statement outside a module
(2 answers)
Closed 2 years ago.
I'm trying to import the PositionalAudioHelper. The code is very basic:
// create the PositionalAudio object (passing in the listener)
import * as THREE from 'three';
var sound = new THREE.PositionalAudio( listener );
var helper = new THREE.PositionalAudioHelper(sound);
sound.add( helper );
The webpack error I get is:
"export 'PositionalAudioHelper' (imported as 'THREE') was not found in 'three'
I installed Three using yarn so it may not install the latest version that includes this commit: https://github.com/mrdoob/three.js/pull/15748
Any ideas on how to do this?
Since PositionalAudioHelper is located on the examples directoy, you have to import it like so:
import { PositionalAudioHelper } from 'three/examples/jsm/helpers/PositionalAudioHelper.js';
three.js R116
I've installed and imported three.js as a module (v0.100.0) like:
import * as THREE from 'three';
...
var d = new THREE.DecalGeometry(. . .);
Getting error message that DecalGeometry is not a constructor.
Looking in src directory for the three module, there is no DecalGeometry anywhere. What is happening?
THREE.DecalGeometry it no part of the core but of the examples directory. You have to include the following file manually to your project:
https://github.com/mrdoob/three.js/blob/master/examples/js/geometries/DecalGeometry.js
The nub of the matter is, what am I doing wrong in the following code snippet?
from tkinter import *
from tkinter.ttk import *
root = Tk()
myButton = Button(root)
myImage = PhotoImage(myButton, file='myPicture.gif')
myButton.image = myImage
myButton.configure(image=myImage)
root.mainloop()
The error message I get from idle3 is as follows:
>>>
Traceback (most recent call last):
File "/home/bob/Documents/Python/tkImageTest.py", line 9, in <module>
myButton.configure(image=myImage)
File "/usr/lib/python3.2/tkinter/__init__.py", line 1196, in configure
return self._configure('configure', cnf, kw)
File "/usr/lib/python3.2/tkinter/__init__.py", line 1187, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TypeError: __str__ returned non-string (type Button)
>>>
This error message has me stumped, I simply don't understand what it is trying to say. Any ideas?
I would also appreciate suggestions for changes...
The error seems to point to the myButton argument passed to PhotoImage. As you noted in your comment, PhotoImage was treating the widget object as a string (there are several options of type string; see a list of PhotoImage options here).
Your code will work if you implement that line without referencing the myButton object:
myImage = PhotoImage(file='myPicture.gif')
I'm not certain you need to alter the PhotoImage constructor. Look at the PhotoImage docs to determine the valid options (i.e. resource names) for that class. Quoting the help file:
Help on class PhotoImage in module tkinter:
class PhotoImage(Image)
| Widget which can display colored images in GIF, PPM/PGM format.
|
| Method resolution order:
| PhotoImage
| Image
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, key)
| # XXX config
|
| __init__(self, name=None, cnf={}, master=None, **kw)
| Create an image with NAME.
|
| Valid resource names: data, format, file, gamma, height, palette,
| width.
FYI: The easiest way to get to the docs from Python at the command line or from IDLE:
from tkinter import PhotoImage
help(PhotoImage)
And lastly, another useful link about this class is at http://tkinter.unpythonic.net/wiki/PhotoImage.
I tested the example with python 2.7.9, 3.2.5, 3.3.5, 3.4.3 in 32bit and 64bit.
(Win 8.1 64bit)
The code works.
( in python 3.4.3 64bit I had first an error message.
I've completely uninstalled 3.4.3 and then reinstalled.
Now, the example works also with 3.4.3 64 bit )
# basic code from >>
# http://tkinter.unpythonic.net/wiki/PhotoImage
# extra code -------------------------------------------------------------------------
from __future__ import print_function
try:
import tkinter as tk
except:
import Tkinter as tk
import sys
import platform
print ()
print ('python ', sys.version)
print ('tkinter ', tk.TkVersion)
print ()
print (platform.platform(),' ',platform.machine())
print ()
# basic code -------------------------------------------------------------------------
root = tk.Tk()
def create_button_with_scoped_image():
# "w6.gif" >>
# http://www.inf-schule.de/content/software/gui/entwicklung_tkinter/bilder/w6.gif
img = tk.PhotoImage(file="w6.gif") # reference PhotoImage in local variable
button = tk.Button(root, image=img)
# button.img = img # store a reference to the image as an attribute of the widget
button.image = img # store a reference to the image as an attribute of the widget
button.grid()
create_button_with_scoped_image()
tk.mainloop()