Maya 2023 pymel I can't access mel2py with python3 - python-3.x

I get this error and I think it's because of python3
Error: AttributeError: file C:\Program Files\Autodesk\Maya2023\Python\lib\site-packages\pymel\tools\mel2py\melparse.py line 438: 'str' object has no attribute 'lineno'
import pymel.tools.mel2py as mel2py
pythonCode = mel2py.mel2pyStr( """
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateX;
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateY;
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateZ;
""",pymelNamespace='pm')
print( pythonCode )

I believe the issue is down to how you're formatting the mel command string. If you use the code below it should function:
import pymel.tools.mel2py as mel2py
mel_command = 'setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateX";setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateY";setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateZ";'
pythonCode = mel2py.mel2pyStr(mel_command, pymelNamespace='pm')
print(pythonCode)

A simple solution is to launch a maya2019 or maya2018 version prior to maya2022 and use mel2py there.

Related

Cannot import name 'Instalysis' from 'instagramy'

I cannot figure out what this error requires... any ideas for a Python newbie? All pre requisites are installed... this is version 3.9 64-bit.
Details: "ADO.NET: Python script error.
ImportError: cannot import name 'Instalysis' from 'instagramy' (C:\Python\Python39\lib\site-packages\instagramy_init_.py)
"
Here's the test script I'm running:
from instagramy import Instalysis
# Instagram user_id of ipl teams
teams = ["chennaiipl", "mumbaiindians",
"royalchallengersbangalore", "kkriders",
"delhicapitals", "sunrisershyd",
"kxipofficial"]
data = Instalysis(teams)
# return the dataframe
data_frame = data.analyis()
data_frame
The instagramy package doesn't have the 'Instalysis' section to it. But it does have these:
from instagramy import InstagramUser
This will give uyou all of the info also I saw that you had parentheses at data_frame = data.analyis()
You will recieve an error if you have them as it isn't an executable function.
Go have a look at the pypi page here: Pypi- Instagramy
Hope this could help!

AttributeError: module 'yagmail' has no attribute 'SMTP'

Why do I get the below error?
I have imported yagmail. I have also tried with importing the smtplib module
Traceback (most recent call last):
File "C:/Users/Darsh/AppData/Local/Programs/Python/Python37-32/class programes/project1/my_yagmail.py", line 1, in <module>
from yagmail import *
File "C:/Users/Darsh/AppData/Local/Programs/Python/Python37-32/class programes/project1\yagmail.py", line 8, in <module>
yag = yagmail.SMTP(user="dar*******#gmail.com", password="*******", host='smtp.gmail.com')
AttributeError: module 'yagmail' has no attribute 'SMTP'
Code:
import yagmail
receiver = "pat*******#gmail.com"
body = "Hello there from Yagmail"
filename = "c.pdf"
yag = yagmail(user="dar**********#gmail.com", password="**********", host='smtp.gmail.com')
yag.send(
to=receiver,
subject="Yagmail test with attachment",
contents=body,
attachments=filename,
)
Looks like you have a script named "yagmail.py", I believe that the error is due to a namespace collision. My script was named the same thing, after renaming it the issue went away.
I saw a similar post on a different page in a different language that solved it (yay Google Translate!).

Adding timestamp to a file in PYTHON

I can able to rename a file without any problem/error using os.rename().
But the moment I tried to rename a file with timestamp adding to it, it throws win3 error or win123 error, tried all combinations but no luck, Could anyone help.
Successfully Ran Code :
#!/usr/bin/python
import datetime
import os
import shutil
import json
import re
maindir = "F:/Protocols/"
os.chdir(maindir)
maindir = os.getcwd()
print("Working Directory : "+maindir)
path_4_all_iter = os.path.abspath("all_iteration.txt")
now = datetime.datetime.now()
timestamp = str(now.strftime("%Y%m%d_%H:%M:%S"))
print(type(timestamp))
archive_name = "all_iteration_"+timestamp+".txt"
print(archive_name)
print(os.getcwd())
if os.path.exists("all_iteration.txt"):
print("File Exists")
os.rename(path_4_all_iter, "F:/Protocols/archive/archive.txt")
print(os.listdir("F:/Protocols/archive/"))
print(os.path.abspath("all_iteration.txt"))
Log :
E:\python.exe C:/Users/SPAR/PycharmProjects/Sample/debug.py
Working Directory : F:\Protocols
<class 'str'>
all_iteration_20180409_20:25:51.txt
F:\Protocols
File Exists
['archive.txt']
F:\Protocols\all_iteration.txt
Process finished with exit code 0
Error Code :
print(os.getcwd())
if os.path.exists("all_iteration.txt"):
print("File Exists")
os.rename(path_4_all_iter, "F:/Protocols/archive/"+archive_name)
print(os.listdir("F:/Protocols/archive/"))
print(os.path.abspath("all_iteration.txt"))
Error LOG:
E:\python.exe C:/Users/SPAR/PycharmProjects/Sample/debug.py
Traceback (most recent call last):
Working Directory : F:\Protocols
<class 'str'>
File "C:/Users/SPAR/PycharmProjects/Sample/debug.py", line 22, in <module>
all_iteration_20180409_20:31:16.txt
F:\Protocols
os.rename(path_4_all_iter, "F:/Protocols/archive/"+archive_name)
File Exists
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'F:\\Protocols\\all_iteration.txt' -> 'F:/Protocols/archive/all_iteration_20180409_20:31:16.txt'
Process finished with exit code 1
Your timestamp format has colons in it, which are not allowed in Windows filenames. See this answer on that subject:
How to get a file in Windows with a colon in the filename?
If you change your timestamp format to something like:
timestamp = str(now.strftime("%Y%m%d_%H-%M-%S"))
it should work.
You can't have : characters as part of the filename, so change
timestamp = str(now.strftime("%Y%m%d_%H:%M:%S"))
to
timestamp = str(now.strftime("%Y%m%d_%H%M%S"))
and you'll be able to rename your file.

`TypeError: 'NoneType' object is not iterable` in `subprocess.call`

I am trying to apply subprocess.call instead of os.system following PEP 324
In a task to open multiple urls
import subprocess
open_chromes = [
'https://en.wikipedia.org/wiki/Embodied_cognition',
'https://docs.python.org/3.6/index.html',
'https://docs.djangoproject.com/en/1.11/',]
for chrome in open_chromes:
cmd = ['open', '-na', 'Google Chrome']
subprocess.call(cmd.append(chrome))
Error reported as
TypeError: 'NoneType' object is not iterable
Alternatively with os.system is definitely easy.
import os
open_chromes = [
'https://en.wikipedia.org/wiki/Embodied_cognition',
'https://docs.python.org/3.6/index.html',
'https://docs.djangoproject.com/en/1.11/',]
for chrome in open_chromes:
os.system('open -na "Google Chrome" {}'.format(chrome))
What's the problem with my code?
The append function of a list does not return anything, so subprocess.call(cmd.append(chrome)) is equivalent to subprocess.call(None), which is the problem. You need to append before doing the call
if you want to keep it a single line and not changing the original array - use + operator
subprocess.call(cmd + chrome)

No attribute 'HookManager'

I am copying the key logger from this video: (https://www.youtube.com/watch?v=8BiOPBsXh0g) and running the code:
import pyHook, sys, logging, pythoncom
file_log = 'C:\Users\User\Google Drive\Python'
def OnKeyboardEvent(event):
logging.basicConfig(filename = file_log, level = logging.DEBUG, format = '%(message)s')
chr(event.Ascii)
logging.log(10, chr(event.Ascii))
return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.Pumpmessages()
This returns the error:
Traceback (most recent call last):
File "C:\Users\User\Google Drive\Python\pyHook.py", line 2, in <module>
import pyHook, sys, logging, pythoncom
File "C:\Users\User\Google Drive\Python\pyHook.py", line 12, in <module>
hooks_manager = pyHook.HookManager()
AttributeError: 'module' object has no attribute 'HookManager'
I am running Python 2.7.11 and a windows computer.
I don't know what the problem is; please help.
Thank you
I found the solution. If you open HookManager.py and change all 'key_hook' words to 'keyboard_hook' no more error occurs
I'm still unsure what the issue is but I found a solution.
If you move the program you are trying to run into the same folder as the HookManager.py file then it works.
For me this file was:
C:\Python27\Lib\site-packages\pyHook
Bro this line is wrong
file_log = 'C:\Users\User\Google Drive\Python'
As the system doesn't allow your program to write to the 'C' drive, you should use another path, like 'D' drive or 'E' drive or etc. as given below.
file_log = 'D:\keyloggerOutput.txt'
I had same message error after having installed pyWinhook-1.6.1 on Python 3.7 with the zip file pyWinhook-1.6.1.zip.
In application file, I replaced the import statement:" import pyWinhook as pyHook" with "from pywinhook import *". The problem was then solved.

Resources