I put a .py using ATOM IDE, called the .py in cmd command and got the following error saying that the module can't be found: Trackback (most recent call last): File "widgets.py", line 5, in from bokeh.layouts import layout ImportError: No module named layouts.
The same syntax ran fine in Jupyter...without warning for layouts module name.
Anyone has a clue? Is it possible my Python version and the bokeh version are compatible?
The code in widgets.py is the following:
from bokeh.io import output_file, show
#create text box on webpage, and text
from bokeh.models.widgets import TextInput, Button, Paragraph
#arrange the widgets
from bokeh.layouts import layout
After a bit investigation, I found that it's because I was using the cmd command line rather than the Anaconda Prompt environment. Now I am in the correct environment, the .py code generates a bokeh server as it is supposed to.
Related
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?
I have a problem with the plotly package. To be precise, I'm using auto-py-to-exe in order to have a file .exe which, if the users asks for it, plots a table using the plotly package. My code goes like this:
import pandas as pd
import plotly.graph_objects as go
import numpy
df= pd.read_excel (r'C:\Users\user\Desktop\Program\Data_Studio_Def.xls')
visualize_table= input('visualize table of patologies? (yes/no)')
if visualize_table== yes
fig = go.Figure(...)
fig.show()
Now, when I run the .exe made by auto-py-to-exe on the CMD (OS: Windows 10), I get some errors regarding modules like
Module plotly.validators.table not found
Once I add all such modules via hidden-import, I get the error:
FileNotFoundError No such file or directory : C\Users\user\output...
so it is searching for the plot in a folder rather than actually print it and I don't know how resolve this. Should I provide further informations?
P.S. I found out that the main problem is caused by the plotly package itself: I tried to build the exe via cx_Freeze rather than pyinstaller and the result was:
Module plotly.validators.table has no Attribute CellsValidators
Doing some searching I found out I'm not the only one with the same problem, the "HasNoAttribute", but uninstalling the package to then reinstall it again didn't do anything unfortunately.
I have seen a lot of questions on this topic, but None seem to explain why this is happening or provide a solution I can use.
The following script gives 8 different outputs depending on where it's run from and I really don't understand why. I've managed to pin down a pattern but still don't understand why this occurs and it hasn't helped me solve the problem.
I have a file called
__init__.py
In the same directory as this file, I have a folder called "source_code". In that folder I have another file called
__init__.py
The
source_code/__init__.py
file contains one line of code which is:
print("source_code imported")
The first
__init__.py
file has the following script:
import sys
print(sys.executable)
print(sys.path[0])
try:
from . import source_code
except ImportError as ie:
print(ie)
try:
import source_code
except ImportError as ie:
print(ie)
I am using Spyder 4.1.5 as part of the Anaconda package, as well as Powershell on Windows 10. I have a virtual environment, created with conda, with only Jupyter notebook and spider installed.
The pattern I have found (as far as I can tell) is as follows:
If I run the script through powershell, from outside the virtual environment, the output is as follows:
C:\Users\user\Desktop\Anaconda\python.exe
C:\Users\user\path\to\file
cannot import name 'source_code' from '__main__' (.\path\to\file\__init__.py)
source_code imported
if I run through Powershell from inside the virtual environment, the output is:
C:\Users\user\Desktop\Anaconda\envs\venv\python.exe
C:\Users\user\path\to\file
attempted relative import with no known parent package
source_code imported
if I open spyder, outside the virtual environment, and run the script by clicking into the editor and pressing "Control+Enter", the output is:
C:\Users\user\Desktop\Anaconda\python.exe
C:\Users\user\Desktop\Anaconda\python37.zip
cannot import name 'source_code' from '__main__' (C:\Users\user\path\to\file\__init__.py)
No module named 'source_code'
If (still in spyder, outside the virtual environment) I click on the run button in the bar at the top, the output is:
C:\Users\user\Desktop\Anaconda\python.exe
C:\Users\user\Desktop\Anaconda\python37.zip
cannot import name 'source_code' from '__main__' (C:\Users\user\path\to\file\__init__.py)
source_code imported
If I then click back into the editor and press "Control+Enter" again, the output is now:
C:\Users\user\Desktop\Anaconda\python.exe
C:\Users\user\Desktop\Anaconda\python37.zip
If I run spyder from inside the virtual environment. Click into the editor and press "Control+Enter", the output is:
C:\Users\user\Desktop\Anaconda\envs\venv\python.exe
C:\Users\user\Desktop\Anaconda\envs\venv\python38.zip
attempted relative import with no known parent package
No module named 'source_code'
Then click on the run button at the top, the output is:
C:\Users\user\Desktop\Anaconda\envs\venv\python.exe
C:\Users\user\Desktop\Anaconda\envs\venv\python38.zip
attempted relative import with no known parent package
source_code imported
Then clicking back into the editor and pressing "Control+Enter" again gives:
C:\Users\user\Desktop\Anaconda\envs\venv\python.exe
C:\Users\user\Desktop\Anaconda\envs\venv\python38.zip
attempted relative import with no known parent package
I have tried including "a=8" in the "source_code/init.py" file and using "from .source_code import a" instead of "from . import source_code".
I have also tried including the lines:
from pathlib import Path as path
sys.path.insert(0, path(__file__).parent)
This changed the output from print(sys.path[0]), but made no difference to the output of the import statements.
I would like to understand the following:
1: Why does
Cannot import name "source_code" from "__main__."
change to
"attempted relative import with no known parent package."
when I move from outside to inside the virtual environment?
2: Why does running the script from Powershell, add the location of the file to the beginning of sys.path, but running it from spyder does not? (see the difference in line 2 between outputs 1 and 2 vs outputs 3 onwards.)
3: In Spyder, what is the difference between clicking into the editor and pressing "Control + Enter" and clicking the Run button.
4: Why can't spyder find the "source_code" module (located in the same directory as the script) when I press "Control + Enter" but it can once I have run it by clicking the run button? (see the difference between output 3 vs output 5, and output 6 vs output 8).
5a: Why (once I have run the script by clicking the run button) does pressing "Control + Enter" stop generating an ImportError but also does not run the script (i.e. it doesn't print "source_code imported" in output 5 and 8).
5b: Why does this behaviour change depending on whether I'm inside or outside the virtual environment. i.e. Why is line 3 different in outputs 4 and 5, but the same in outputs 7 and 8?
6: How do I get my script to consistently, successfully import the "source_code" module, regardless of where I run it from?
I've been searching for it but could not find anything on the net on this topic.
When I'm working on a programm in python 3.5 which imports tkinter or pyglet I'm perfectly able to start it from the command line on my Linux Mint installation. As soon as I try to start it from pycharm or Visual Studio Code I get an error.
It is for tkinter:
Traceback (most recent call last): File "/home/b...", line 3, in <module>
import tkinter as tk
File "/usr/lib/python3.5/tkinter/__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'
Both, the tkinter and the pyglet script, are working when they are started from idle3 (with F5).
Can anyone help me out?
Best
B.
i'm having the same issue. The problem lie with Linux Mint Software Manager. If your vs code is install via Software Manager, it will be install in Flatpak virtual sandbox. Just download and run vs code from its homepage will do.
I know there's already a question like this but the answer didn't work for me.
When I append the py2exe argument in the program, and run it, I noticed it's missing a bunch of files. Also when I run the exe, it says
File "boot_common.py", line 46 in <module>
ImportError: No module named 'ctypes'
Can anyone help me on how to fix this? Here's my code:
from distutils.core import setup
import py2exe, sys
import tkinter as tk
from tkinter import filedialog
input('Press Enter to continue and select your Python file you want to convert when the dialog shows up...')
tk.Tk().withdraw()
file_path = tk.filedialog.askopenfilename()
sys.argv.append("py2exe")
setup(console=[file_path])
Also if it helps, I'm using a 32-bit Python interpreter.