WinRT CoInitialize in Python - python

I have the following simple code:
import winrt.windows.applicationmodel.datatransfer as DataTransfer
clipboard = DataTransfer.Clipboard
print(clipboard.clear())
And am getting this error, any idea how to fix?
print(clipboard.clear())
RuntimeError: CoInitialize has not been called.

Related

kubeflow AttributeError: 'ComponentStore' object has no attribute 'uri_search_template'

I am trying to load some prebuit gcp kubeflow components using kfp.components.ComponentStore. However I am getting this error:
line 180, in _load_component_spec_in_component_ref
if self.uri_search_template:
AttributeError: 'ComponentStore' object has no attribute 'uri_search_template'
when at this line of code:
mlengine_train_op = component_store.load_component('ml_engine/train')
KFP version:
kfp 1.8.10
kfp-pipeline-spec 0.1.13
kfp-server-api 1.7.1
Steps to reproduce
import kfp
from kfp.components import func_to_container_op
COMPONENT_URL_SEARCH_PREFIX = "https://raw.githubusercontent.com/kubeflow/pipelines/1.7.1/components/gcp/"
component_store = kfp.components.ComponentStore(
local_search_paths=None, url_search_prefixes=[COMPONENT_URL_SEARCH_PREFIX])
mlengine_train_op = component_store.load_component('ml_engine/train')
mlengine_deploy_op = component_store.load_component('ml_engine/deploy')
I got this code from an example that was running on kfp 0.2.5. This is probably some version problem but does anyone knows how to update this code to the newer version?
I solved the issue. It is something that #Kabilan Mohanraj also mentioned is his comment. It looks like there is a bug if you don't set up uri_search_template when creating the ComponentStore.
I solved it by providing it as parameter, it doesn't really matter what you pass to the constructor really, but it is required because in the code there is the following
if self.url_search_prefixes:
but if you don't pass something that attribute doesn't get created in the constructor.
I fixed it like this:
component_store = kfp.components.ComponentStore(
local_search_paths=["local_search_path"], url_search_prefixes=[COMPONENT_URL_SEARCH_PREFIX]), uri_search_template="{name}/"
I hope it will help someone in the future.
I suggested in the github issue to address this by either make the error more clear or to have better check on uri_search_template attribute.

Metatrader5 - Python Integration - symbol_total() returns None

I'm trying to get the number of symbols of metatrader5 and I'm getting an error
TypeError: '>' not supported between instances of 'NoneType' and 'int'
Link to the documentation: https://www.mql5.com/en/docs/integration/python_metatrader5/mt5symbolstotal_py
code:
import MetaTrader5 as mt5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
symbols=mt5.symbols_total()
if symbols>0:
print("Total symbols =",symbols)
else:
print("symbols not found")
mt5.shutdown()
The problem is that the function is returning NoneType instead of a number.
Why it's returning a NoneType? How can i get the list of Symbols/Stocks?
Any clue?
I had the same problem too. If you are currently using a downloaded MT5 terminal from your broker, you can try using the official MT5 terminal instead. That seemed to have fixed my issue. Don't forget to specify the path to the correct MT5 terminal.exe afterwards within the initialization function initialize(path=...).
As to why this was causing an issue, I'm unsure myself. I happened across this post and it mentioned that there may have been modifications made by brokers.
Anyway, hope this works for you too!
To connect to your broker's server afterwards, within the MT5 terminal under Navigator->Accounts (Right Click)->Open an account->Search for your broker and enter your credentials.

Using TriangulatePoints with SFM with Python

I'm trying to use the built in opencv function TriangulatePoints for multiple views: https://docs.opencv.org/3.4.4/d0/dbd/group__triangulation.html#ga211c855276b3084f3bbd8b2d9161dc74.
Using python on linux, does anyone have experience using this function? The website only has the syntax for cpp and in python I don't know how to code it.
My code now:
import cv2
import numpy as np
point_2D = np.array([[17.4485, 709.7993], [17.4382, 709.8409]])
Proj_Matrices = np.array([ [1037.5, -6.9927, -10.0190, -4780.7], [6.9747, 1043.3, -5.8867, -731.9206], [644.7895, 383.4982, -3231.1], [1036.937, -22.8371, -28.3254, -5607.7], [23.0587, 1043.1, 3.1815, -633.4485], [650.4355, 373.6, -15.3504, -3706.5] ])
OutputArray = np.zeros((3,2))
Points_3D = cv2.sfm.triangulatePoints(point_2D, Proj_Matrices, OutputArray)
However, when I run it from the terminal I get the following error:
AttributeError: module 'cv2' has no attribute 'sfm.
I installed sfm on my computer using the instructions on the opencv site.
When I omit sfm I get the following error:
AttributeError: module 'cv2' has no attribute 'sfm'
I think I get that error since the machine thinks I'm trying to use the previous version of TriangulatePoints.
Examples of opencv code using sfm exist on the opencv website but they are in cpp.
I'm wondering what the syntax for using TriangulatePoints(with sfm) is in python? Even in cpp, I don't understand how the output array is an input to the function? Also, if anyone knows how to fix the sfm error I am receiving that would be appreciated.
Thanks!

Python package function does not match C++ signature

I am trying to read a configuration file with the Pyrfa Python package. This is my code:
import pyrfa
p = pyrfa.Pyrfa
p.createConfigDb("./pyrfa.cfg")
p.acquireSession("Session1")
p.createOMMConsumer()
This code has been copied from https://github.com/devcartel/pyrfa.
When running this code, I get the following error message.
Boost.Python.ArgumentError: Python argument types in
Pyrfa.createConfigDb(str)
did not match C++ signature:
createConfigDb(class Pyrfa {lvalue}, class boost::python::api::object)
It somehow suspect that this has not so much to do with the Pyrfa package. Does anybody have an idea?
Thanks so much!
I think you're only missing ()
p = pyrfa.Pyrfa()

"PortMidi: `Bad pointer'" when closing mido port

My code:
import mido
import time
mido.set_backend('mido.backends.pygame')
output = mido.open_output()
output.send(mido.Message('note_on', note=64, velocity=60))
time.sleep(3)
output.close()
After the last line, the following error is printed:
Exception Exception: "PortMidi: `Bad pointer'" in <pypm.Output object at 0x025FF0B0> ignored
Apart from that, everything seems to work fine. However I'm developing a console app and this output is annoying. How can I get rid of this error?
I am using Windows 7 and Python 2.7.
You don't even have to set the RtMidi backend as it is the default, see mido backend documentation

Categories