I'm on Windows using Python version 3.4.2. My Matplotlib is not importing in my file when I run it in the cmd, but it seems to work when I import from the python shell. I'm not sure if my path is messed up somehow. Whenever I run it in the cmd, it produces the following error:
F:\pypractice> py montecarlo.py
Traceback (most recent call last>:
File "montecarlo.py", line 2, in <module>
import matplotlib
ImportError: No module named matplotlib
Again, it works in the python shell, so it probably is a PATH problem. The path I have in my environment variables is F:\Python34\;F:\Python34\Scripts\; I was told to install the following modules: numpy, pyzt, dateutill, setuptools, and six. This fixed the importing error in the python shell.
All of my modules are placed in F:\Python34\Lib\site-packages.
Any help with fixing this problem would be greatly appreciated. Thank you.
I was messing with the wrong variable. Simply placing #!/usr/bin/env python at the top of my file fixed the problem.
Related
The skopt package (https://scikit-optimize.github.io/stable/install.html) was installed on a cluster I use.
When I run the code in python directly in the terminal (i.e., cluster terminal), no problem occurs and the code works as expected.
However when I simply place the command to execute the code in a PBS queue system file (e.g., python3 ./code.py), I cannot load the installed package and I get the following message:
Traceback (most recent call last):
File "./test.py", line 22, in <module>
from skopt import gp_minimize
ModuleNotFoundError: No module named 'skopt'
Could someone give me an insight on how to solve the problem?
If I need to provide any more information, let me know.
ps1: the packages is installed on /usr/local/lib/python3.6/site-packages/skopt directory.
ps2: I tried to load export PYTHONPATH=$PYTHONPATH:[$HOME]/.usr/local/lib/python3.6/site-packages/skopt into the PBS file and it didn't work.
This has happened to me before but its a pretty simple fix
pip3 converts to python3
pip converts to python
Use those commands instead of random. Check my comment for further details.
The solution was easier than I thought, as the skopt package was in the path "/usr/local/lib/python3.6/site-packages/" just use the command "export PYTHONPATH=$PYTHONPATH:/usr/local/ lib/python3.6/site-packages", before running the code in python
I was using the "export" command wrongly.
As usual, I opened Notepad++ and wrote my python code. Then when I opened my CMD to execute it, I got this error
`Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\Lib\site.py", line 73, in <module>
import os
ModuleNotFoundError: No module named 'os'
I uninstalled and reinstalled python hoping that it'll run, but it didn't. Can anybody please help!
EDIT: Python doesn't work on my pc. Whenever I type "python" in the CMD, it would throw this error, IDLE is also not opening. And yes, my python is added to PATH so please don't say to add it to the path.
Try to run this snippet
import os
output = os.environ['HOME']
print(output)
If this is not working then there is issue with your python installation. You need to re-install it.
To get comfortable with python modules you can learn from here
I'm learning python3 (--version 3.7.3) and I'm using Anaconda 3 (conda --version 4.8.2) on a Windows 10 computer, writing with Sublime Text 3.2.2.
If I can use matplotlib from the command line, and other files with the same import statement worked fine, why would I suddenly keep getting error messages when I try to build my .py file where the first line is
import matplotlib.pyplot as plt
or
from matplotlib import pyplot
My error message is
ModuleNotFoundError: No module named 'matplotlib'
Meanwhile, the same program done interactively while in the SAME directory, no problema. And to make it even weirder, other files in the same folder with the same import statement, worked fine. Now, however, they are giving me the error message.
I've renamed the folder I was saving my files in and renamed or moved files around a bit, but that's pretty much the only change. Would I have to reinstall every time I move a file or rename a folder? Could it be a problem with Sublime, since the command line is working?
Please explain like I'm 5 and in remedial kindergarten.
i'm having the same issue with anacodna distribution when trying to use SUblimetext 3.
Simple file tst.py 1 code line import matplotlib.pyplot as plt received an error message (C:\Local\Anaconda3\lib\site-packages\numpy_init_.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL .....)
But when using the same tst.py with Spider or JUpeter it works.
I'm trying to bundle my script into a .app using Tkinter as the GUI and the wrapper that does the bundling is Platypus.
I'm getting this error when I go to run the app.
Traceback (most recent call last):
File "/Users/samb/Desktop/Beta1.app/Contents/Resources/script", line 4, in <module>
import tkinter
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/P...ework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I'm running Python 3.7.4 on this machine, and my script uses:
import tkinter
from tkinter import filedialog
which should make it compatible. The script works when I run it using terminal, just not when I run the app.
I've specified in the bundling app that it should use python3 as well...
Not sure what I'm doing wrong here?
Several problems: There is no file at /usr/bin/python3. Either use /usr/local/bin/python3 or /usr/bin/env with python3 as args. Or whatever your particular python environment needs.
For some reason, python is looking for the library inside Xcode, which is unusual. I have python3 installed and there's no python in
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/
On my installation, the valid filepath is:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py
(i.e. in /Library, not inside Xcode.) As the script works in Terminal, it's likely that Platypus's config is wrong somehow.
As a quick hack, I suppose you could symlink Python.framework from /Library/Frameworks to the Frameworks folder inside Xcode.
As stated in the comments, you don't need to include the first import line. Currently, you're importing all of tkinter, and then importing just the filedialog. The whole point of from is to avoid importing the entire library.
Brand new to Python, coming from Ruby.
I have a script that works perfectly if I run it form ipython or ipython qtconsole. I then tried to turn it into an executable script -- threw #!/usr/bin/env python at the top.
Running the script throws an error:
$ ./script/myscript.py
Traceback (most recent call last):
File "./script/myscript.py", line 6, in <module>
import yaml
ImportError: No module named yaml
Obviously there's something wrong with how python is loading modules (as it works perfectly fine from the REPL) but I have no idea how to fix it.
Thanks!
What is likely happening is you have more than one version of Python installed on your system, and the yaml module is only installed in one of them. When you run ipython it's using one version, but your script's shebang line is finding another version. Run
head `which ipython`
and see if it matches up to the result of which python (I'm betting it won't). Once you know the path to the python binary being used by ipython, you can specifically define it in your script's shebang line.
As a long-term fix, edit your $PATH variable and put the directory containing your desired version of Python ahead of the directory shown by which python, so that you can continue to use #!/usr/bin/env python as a shebang.
ipython must be pointing at a different version of python than what is in PYTHONPATH.
You can find out by looking at cat /usr/local/bin/ipython.
Look at
ipython reads wrong python version