I've been animating evolution of surfaces (stored as 3d numpy arrays) using matplotlib, but this method is slow and clunky. I gather that VPython and MayaVi are better alternatives, but apparently neither is available yet in Python 3.4 (which is what I'm using). Are there any good ways to perform 3d animation in Python 3.4?
You can get the vpython working in python3.4 now. Follow this steps:
Preparation
Download the four packages TTFQuery, FontTools, and Polygon ,vpython in get the requisites packages to same directory.
Installation
Run cmd
cd path/to/package_downloaded_directory
pip install packagename.whl
Find the file C:\Python34\lib\site-packages\vis\materials.py
Open the file in an editor, then go to line 70
Comment the two lines just like this
class raw_texture(cvisual.texture):
def __init__(self, **kwargs):
cvisual.texture.__init__(self)
# for key, value in kwargs.items():
# self.__setattr__(key, value)
Save the changes
Note that when when you use vpython to code a script, the first line must be like below:
from vis import *
Below is my code sample
from vis import *
sphere(pos=vector(0,0,0),radius=0.5,color=color.red)
arrow(pos=vector(0.5,0,0),axis=vector(1,0,0),color=color.green)
Related
I am new to Deep Learning and I have just installed tensorflow on my Mac,
however, there are some problems.
I am sure I installed successfully because I can run tensorflow on Terminal using python 3.5
import tensorflow as tf
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)
there is an output on my bash
Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)
However, when I run import tensorflow as tf on Python Console of PyCharm. A problem occurred:
>>> import tensorflow as tf
ImportError: No module named 'tensorflow'
I just went through this a few days ago after switching to PyCharm. You have to select the right Project Interpreter so it can find the Python installation that includes Tensorflow. In the menu go to PyCharm->Preferences and under the section Project: PyCharm on the left select Project Interpreter. In my case, I select 3.5.2 (~/anaconda/bin/python) because there's where my Tensorflow seems to reside. Whatever versions you select, scroll through the window at the bottom to make sure you see Tensorflow listed as a Package.
IMPORTANT: in my case it seems that once you OK this, it takes a while for PyCharm to digest? Because for a while the 'Run' button is greyed out and you can't run your program. Took me a while to figure what I'm doing wrong, but looks like you just need to give it sometime and it picks it up and the Run button goes back to green. Hope this works for you...
I am using the Community Edition, for what it's worth...
I'm using PyCharm 2018.1.4 Community Edition on Fedora 28, and have TensorFlow 1.9.0 installed (through "sudo pip3 install --upgrade tensorflow"). Here is my step to load TensorFlow
File > Settings > Project > Project Interpreter > Change to "/usr/bin/python3.6" in Project Interpreter, then the installed Package will be loaded and displayed.
Good luck.
My knowledge of Python is still pretty basic, and I am only now trying to wrap my head around how to use / call libraries from within Maya. (Because I need to create a basic UI from QT Designer and have it be opened in Maya after converting it to a .py file)
After I learned to properly convert a .ui to a .py, I now get this error in Maya
"Module use of python34.dll conflicts with this version of Python"
I tried following what was said here and here, but even then - after setting these environment variables...
PYTHONHOME = C:\Program Files\Autodesk\Maya2016\bin\maya.exe
PYTHONPATH = C:\Python34
... I a still unable to run a basic .py file. In fact - as long as the PYTHONHOME variable is in effect, Python from within Maya no longer does anything.
This code below is the resulting python file that I got from converting the .ui file that I saved out of QT Designer.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.4.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
I've come across some different online notes that advised the use of PySide, and after trying to use:
from PySide.QtCore import *
from PySide.QtGui import *
I still couldn't test if this works, because apparently QtWidgets isn't a module?
I'm pretty lost. The bigger picture is that I just want to be able to run a ui created from QT Designer from Maya's script editor. I have no idea where to begin with learning about libraries. Would anyone here be kind enough to give some advice?
Additional info:
I am using Maya 2016, running on a Windows 10 64 bit OS.
I also have a Python 2.7 in my C: drive
And I am using PyQt5-5.4.1-gpl-Py3.4-Qt5.4.1-x64
Thank you for your time.
Maya's python interpreter is in the 2.7 series (or 2.6 for Maya 2013 and earlier). Your PYTHONPATH is pointing at a python 3.4 install. You also want to make sure that if your Python 3.4 is in PATH it comes later than the maya python install location. This is all to makes sure that Maya doesn't get confused and try to run python 3 code or dlls which it cannot handle.
Also, maya 2016 is running on PyQT4. Maya 2017 runs on PyQT5. So you'll probably want to use a PyQT4 version of designer
Related:
UIC / PyQT4 example
using UIC files in Maya pyQT 4
re: 2017/QT5
I have python2.7.8 on mac, things I did:
sudo easy_install pip - worked.
pip install numpy:
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I also did "pip upgrade numpy" - no luck. What's wrong?
Your problem is a conflict of different Python versions.
I would recommend installing Python and all the packages, such as numpy, scipy, matplotlib, pandas, etc via Brew
See this tutorial: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md
You can verify which Python you're running with which python or which python3 in Terminal.
This solution is more flexible and cleaner in my opinion than using Conda/Miniconda. However it is also a bit more lengthy to install, as you need to have Xcode, devtools installed to build everything
Could it be that you have multiple versions of python installed? What happens if you run python using the full path like this:
$ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
instead of just python2?
In my experience on Mac (and other OS too) it is best to go with Anaconda / Miniconda. This is especially true for packages like NumPy and others from scientific stack.
While Anaconda is a full-blown distribution with about 200 packages, Miniconda is just Python with a few basic libraries. The big advantage is that all packages install as binary. Further, it makes it very simple and stable to install multiple Python versions side by side. For example:
conda create -n py27 python=2.7
creates a new environment with Python 2.7. Activate with:
source activate py27
Now:
conda install numpy
installs NumPy cleanly.
You can do the same for Python 3.5 and switch between environments with source activate.
After jumping from one stackoverflow answer to another I found the solution!
my problems were:
numpy at different location( actually at right, expected-to-be location). It was the IDLE that looks for its own default folder where python2.7 installed.
I checked that my numpy is working like this, run this script to check it is working:
import os
import sys
import pygame
sys.path.insert(0, '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
import numpy
pygame.init()
print "( using __version__): " + numpy.__version__
print numpy.version.version
user_paths = os.environ['PYTHONPATH']
print(user_paths)
sys.path insertion adds additional path to IDLE, so it knows where to look for numpy.
Then I check if numpy truly imported - i just print its version. Right now it is 1.8.0rc.
I want to find a way to avoid using this syspath insertion all the time.
So far so good - for now.
I had a similiar problem with numpy. However, it was resolved by choosing the right environment. If you are using VScode, open the command palette (ctrl+shift+p) and type
Python: Select Interpreter.
From there, try choosing the right virtual environment/Interpreter.
Using python 2.6 on my mac the following works fine (i.e. a plot window opens):
import matplotlib.pyplot as plt
from numpy import linspace, sin, pi
plt.ion()
print "Is interactive:?", plt.isinteractive()
x = linspace(-pi, pi, 1001)
plt.plot(x, sin(x))
raw_input() #keep the window open
It works when I run it in shell (i.e. $ python test.py) as well as when I run it in an interactive python terminal.
I recently installed python 2.7 and with it nothing happens (more precisely, plot window appears in Dock, but doesn't open) when I run my script from shell. The value of plt.isinteractive() is false even after plt.ion().
When I run the same code in an interactive python terminal, everything is fine.
The answer to this question makes the plot window appear, but I find it annoying that now I have to add plt.pause(0.1) to my script.
Is there a way to get the earlier behaviour without modifying the code?
The backend is macosx.
It seems that this is a bug related to matplotlib 1.4. An ugly workaround is to include:
import sys
sys.ps1 = 'SOMETHING'
before importing matplotlib.
Alternatively, one can use ipython to run the script.
For more details see here https://github.com/matplotlib/matplotlib/issues/3505
I am having a problem with tkinter.ttk on mac. I am using macports and python3.1. When I try to use tkinter.ttk I get very old looking gui elements.
eg: I get this
Instead of this:
The code I used is:
from tkinter import *
from tkinter import ttk
root = Tk()
button = ttk.Button(root, text="Hello World").grid()
root.mainloop()
I would be happy to provide any information from my computer needed to answer this question. As I am a novice programer please tell me where to find said information.
I have a Macbook 5,2 with Snow Leopard installed. Any help would be appreciated.
Thanks, Marlen
Question Update:
I installed tk #8.5.9_0+quartz as schlenk suggested only to get this error:
TclMacOSXNotifierAddRunLoopMode: Tcl not built with CoreFoundation support Abort trap
I fixed this error with the patch from https://trac.macports.org/ticket/22954. I followed the instructions to the letter(they are):
$ cd /opt/local/var/macports/sources/rsync.macports.org/release/ports/lang/tcl
$ sudo patch < ~/Downloads/tcl.2.patch
$ sudo port install tcl
This created a new error which is:
Traceback (most recent call last):
File "hello.py", line 5, in <module>
root = Tk()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 1632, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable tk.tcl in the following directories:
/opt/local/lib/tcl8.5/tk8.5 /opt/local/lib/tcl8.5/tk8.5/Resources/Scripts /opt/local/lib/tk8.5 /opt/local/lib/tk8.5/Resources/Scripts /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/Contents/lib/tk8.5 /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/Contents/lib/tk8.5/Resources/Scripts /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/lib/tk8.5 /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/Contents/library
/opt/local/lib/tk8.5/tk.tcl: version conflict for package "Tk": have 8.5.7, need exactly 8.5.9
version conflict for package "Tk": have 8.5.7, need exactly 8.5.9
while executing
"package require -exact Tk 8.5.9"
(file "/opt/local/lib/tk8.5/tk.tcl" line 20)
invoked from within
"source /opt/local/lib/tk8.5/tk.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $file]"
This probably means that tk wasn't installed properly.
The problem might be macports. There are three versions of Tk you could use as the basis for your ttk. The screenshot looks a lot like the older X11 Tk, not the aqua based Tk.
1. Tk via X11.
2. Tk compiled with Carbon 'windowingsystem -aqua'
3. Tk compiled with Cocoa
So you should try to either build a Tk variant 'quartz' via macports or you should get some prebuilt version (e.g. ActiveStates) that has the right version already built.
So try:
sudo port build tk #8.5.9+quartz
Have a look at tutorials here for some more guidance:
http://www.tkdocs.com/tutorial/install.html#installmac
try
style = ttk.Style()
print(style.theme_names())
style.theme_use('default') # change 'default' to something better
I haven't played with ttk, however I have a decent amount of experience with tkinter. I belive you have to fill out the style keyword argument.
I think it would look something like this.
from tkinter import *
from tkinter import ttk
root = Tk()
button = ttk.Button(root, text="Hello World", style="somestyle").grid()
root.mainloop()
Link to some relevant documentation:
http://docs.python.org/release/3.1.3/library/tkinter.ttk.html