Cant import FreeCAD to Python - cad

Im having a little problem when I try to import from a Python file, which is placed in an another folder, to FreeCAD.
Python file location : c:/users/workspace/main.py
FreeCAD : c:/program files (x86)/FreeCAD0.13/bin
when I'm trying to import with the command from FreeCAD import * ( I'm appending FreeCAD's path to sys sys.path.append (" path-To-FreeCADs-BinFolder " )
I get an error :
FreeCAD 0.13, Libs: 0.13R1828
Initialization of FreeCAD failed:
While initializing FreeCAD the following exception occurred:
''module' object has no attribute 'PrintError''
Please contact the application's support team for more information. "
But when i create a Python file in FreeCAD 's folder it works. I mean with import FreeCAD like I wrote above.
ps : My Python Version is 2.7.5 and FreeCAD is : 0.13

I had the same problem and surfing around I found that Win version doesn't support Python2.7, so you have to install Python 2.6, open a shell and do the same
import sys
sys.path.append('C://Program Files//FreeCAD0.13/bin')
import FreeCAD
Then it should work

Related

Tcl/Tk improperly installed error when using Auto-py-to-exe

I am trying to create a EXE file using auto-py-to-exe (pyinstaller). My script implements tkinter to create a GUI. However, when I run pyinstaller, this error message appears.
AttributeError: partially initialized module 'tkinter' has no attribute 'Tk' (most likely due to a circular import)
975818 ERROR: Tcl/Tk improperly installed on this system..
I have viewed solutions however none of them are working for me.
I found this page to be helpful:
PyInstaller exe returning error on a Tkinter script
However, I cannot find the file locations on my computer and do not think they exist.
binary='/System/Library/Frameworks/Tk.framework/Tk':'tk'
--add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' your_script.py
I did find a script called tcl_Tk.py and it is associated with hooks
I read that script and found this:
TODO Shouldn't these be fatal exceptions?
if not tcl_root:
logger.error('Tcl/Tk improperly installed on this system.')
return []
if not os.path.isdir(tcl_root):
logger.error('Tcl data directory "%s" not found.', tcl_root)
return []
if not os.path.isdir(tk_root):
logger.error('Tk data directory "%s" not found.', tk_root)
return []
I do not have tk_root or Tcl_root installed. And have been using tkinter from Anaconda Navigator (anaconda3) environment
Other background information:
I am using Spyder(3.8) as my IDE
Imports:
import tkinter as tk,
import pandas as pd,
from PIL import Image, ImageTk,
import matplotlib.pyplot as plt,
plt.style.use('ggplot')
Any solutions how I can get this to work?

Error with python executable : cannot import name ttk from tkinter

I have a python (3.8.3) script which works perfectly. However, when I create an executable with the following command :
pyinstaller --onefile gui.py
I get the following error : **
cannot import name ttk from tkinter
The error appears at this line :
from tkinter import ttk
I can not remove the import as "ttk" is really needed in my program.
I tried to create it with cx_freeze but I get the same error.
Do you have any solution for this problem ? Thanks.
Try one of these ways to compile your script:
pyinstaller --onefile gui.py --hidden-import=tkinter.ttk
pyinstaller --onefile gui.py --hidden-import=tkinter
If you tackle another import problem it would be better to compile using .spec file where you can specify hidden imports

ModuleNotFoundError when run python script but in cmd prompt type 'import colorama' is works

Window10 and Python3.7.4
The lib I am trying to use is 'colorama'.
When i run the python script file (x.py) it cannot find the module in the line which is "import colorama", but when i open a cmd and enter python env then type 'import colorama', it works. Does any one know what's the reason?
'''
>>>D:\Scratch\commands>mypythonscript.py
>>>Traceback (most recent call last):
>>> File "D:\Scratch\commands\mypythonscript.py", line 12, in <module>
>>> from colorama import init, Fore, Back, Style
>>>ModuleNotFoundError: No module named 'colorama'
'''
I don't know why this issue arise but maybe I installed VS2019. Before this, it worked fine for me.
Try to find which python your are working with using SYS module with its VERSION method in this way:
import sys
print(sys.version)
And then verify if you are using the same python version as you are using on cmd.
Another problem could be the path of your module, try to locate it with the "magical method" of your module installed, for example in this case:
import colorama
print(colorama.__file__)
And then verify if colorama is in this path: ".../Python37/lib/site-packages/colorama"
if not, download COLORAMA from here:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
unzip it with 7ZIP
and all unzip files copy to : ".../Python37/lib/site-packages"
don't worry for the module version, colorama is for all python versions.
NOTE: this only works for windows version.

How to use PyQt4 with Python 3.6?

I need to import PyQt4.QtGui, PyQt4.QtCore and PyQt4.QtWebKit for my script.
since i couldnt find a 3.6 version of PyQt4, i used the latest PyQt4 release i got:
PyQt4-4.11.4-gpl-Py3.4-Qt4.8.7-x64
When i tried to run my script it says
from PyQt4.QtGui import *
ImportError: DLL load failed: module not found.
i tried several "solutions" and read everything i found, but until now nothing helped.
Can't PyQT4 (x64) be used under Win10 Home with Python 3.6 (x64) being installed?
Or did i miss something?

PyQt4, Python 3.4 on Windows 7

I ran the windows 64bit installer for PyQt4 pointing it to the python34 folder. Python is not in default location, so I added PYTHONPATH with D:\Program Files\Python34\Lib\site-packages\PyQt4
Added the import statement to my module: "from PyQt4 import QtGui". I execute and get: "from PyQt4 import QtGui ImportError: DLL load failed: The specified module could not be found."
I noticed that if I simply put import PyQt4 and use intellisense in IDLE there are only a few private methods visible.
Since I ran the installer, must I still perform a make? Readme references windows instruction that do not seem to be present on my machine.

Resources