I'm a complete beginner to coding, Python, and anything beyond user-level computing. I've been learning to code with Python and everything was fine until I tried to import a module outside of Python's Standard Library (pyglet).
pip install pyglet worked and now returns:
> Requirement already satisfied: pyglet in
c:\users\nick\appdata\local\programs\python\python38-32 (1.5.7)
Then I received an error message when running the module in PyCharm.
>C:\Users\Nick\venv\Scripts\python.exe C:/Users/Nick/PycharmProjects/learning1/leaning1.GUI.py
Traceback (most recent call last):
File "C:/Users/Nick/PycharmProjects/learning1/leaning1.GUI.py", line 1, in <module>
import pyglet
ModuleNotFoundError: No module named 'pyglet'
Process finished with exit code 1
I think there are a few possible sources for the issue.
I think I might be saving files in multiple directories, so PyCharm is unable to find what I need. If that's the problem please direct me to a resource on learning how to organize files on my computer (something very basic about directories because I know nothing).
I installed python via python.org, but then Microsoft Store was being opened automatically when I tried to check my python version in the command line. I also downloaded Python from Windows Store.
I tried to solve my problems by completely uninstalling PyCharm, Python (windows store), and Python (python.org). I also tried to delete all previous .py files. I don't think I located everything.
I messed with the interpreter settings in PyCharm.
What I really want is to just start over from a clean slate by scrubbing all Python things!
There are a few steps you should take to prevent this sort of issue:
Use a virtual environment: steps to create a virtual environment
Verify that PyCharm's project interpreter is the virtual environment you just created (in my example, the project is named cheetah and the virtual environment is also named cheetah):
Related
I'm using Anaconda. I created an environment called ENGINEERING. In than environment I installed python 3.6, pandas 1.1.3, spyder 3.3.6, numpy 1.19.2, and many more. The base environment has these packages also but not necessarily the same version. Within the ENGINEERING env I created a python script in Spyder that runs without any issues when I run it in spyder. Then, I want to automate that script by creating a .bat file and then using that to automate via windows task scheduler. My .bat looks like this:
"C:\Users\alopo000\Anaconda3\envs\engineering\python.exe" "C:\Users\alopo000\Files\Python\Valid\Portf.py"
pause
when I run the .bat I get an error message:
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "C:\Users\alopo000\Anaconda3\envs\engineering\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
I've tried many things to fix this. I went to the website they suggested and couldn't find anything there. I uninstalled pandas and numpy and reinstall them again but still, same error. The one thing I haven't tried is to fix the VARIABLE PATHS, mostly because I've read in many places not to change those. I can change them if that's what it is, but I would like to understand first why it is not recommended. I read it can create issues with other versions of python but not sure if that's what it is.
Do I need to activate the environment in the .bat file? is the problem that the .bat file is trying to run it outside the environment? Any help would be appreciated.
You will need to upgrade/change your base Python & numpy version installations to match those specified (3.6, 1.19.2). I had the same issue and same situation as OP (write/dev program in a virtual Spyder environment "spyder-env", then automate .py file with WTS). I tried copying over & running the 'activate.bat' in the /scripts/ folder of the virtual environment but that didn't work. In my situation, my conda spyder-env was Python = 3.9.12 and numpy = 1.21.5.
I ended up upgrading my base global Python version (conda install) for Python which changed from 3.8.3 and did the same with numpy (had to downgrade). I'm not sure if this is exactly necessary, why this works, or if it may cause problems down the line (I was about to just re-install conda).
The appropriate .bat file should be something like this once you do that:
call "C:\Users\alopo000\Anaconda3\Scripts\activate.bat"
call "C:\Users\alopo000\Files\Python\Valid\Portf.py" %*
REM Uncomment below to debug
REM pause
From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.
I'm installing a Python (2.7.8) environment locally in my home folder on a server, in order to use newer versions of Python and some of its libraries (Numpy, Theano) together with OpenBLAS. For this, I first installed Python in the folder usr in my home directory (/home/my_home/usr/) as described here:
https://mail.python.org/pipermail/tutor/2002-March/012903.html
The installation seems to have gone smoothly. I checked this by starting the Python interpreter, which displays the right version on startup.
Following this, I installed OpenBLAS into /home/my_home/opt folder as described here:
Compiling numpy with OpenBLAS integration
... which also didn't give me any errors. However, now when I try installing Numpy (according to the instructions in the above link), I get the following error:
Traceback (most recent call last):
File "setup.py", line 22, in <module>
import subprocess
File "/home/ext_sxc/usr/lib/python2.7/subprocess.py", line 427, in <module>
import select
ImportError: No module named select
I suppose the straightforward thing to do is to find the package for select, compile and install it. I'm not sure if this is the right thing to do because the last time I installed Python 2.7.6 locally in a home directory, there were no such errors. As I understand, the select module should have been installed along with Python.
This also happens when I try installing IPython in a similar way in my home folder. The library which gives the ImportError is different.
I'm wondering if these are related to a more general mistake I may have made while installing Python. I'd appreciate any advice on this issue. Please let me know if any additional information would help. Thanks!
I am trying to import Tktable in Python 2.7.
I have put the Tktable.py file within my project folder. Last time, when I was using Canopy, it is working perfectly. After I changed to PyCharm and uninstalled Canopy, a lot of libs went wrong, I have successfully fixed all the others except Tktable.
Can anyone helped me?
Here is the error I got:
File "/Users/XXX/XXX/XXX/project/Tktable.py", line 121, in __init__
master.tk.call('package', 'require', 'Tktable')
TclError: can't find package Tktable
The libraries available from PyCharm depend on your Project Interpreter.
A quick check is to use the Project View (Tool #1), and browse the External Libraries. If the library is not there, you can try to:
Add the location of your library, via Preferences.../Project Interpreter/Python Interpreters (paths tab)
(Re)install the library from PyCharm, again via Python Interpreters (packages tab).
Set another interpreter for your project, if one of them has your library already.
Install the library from outside PyCharm, for the right python version.
I'm trying to follow this tutorial and I'm getting the following error:
ImportError: No module named django.core.management
I'm completely new to python. I believe Visual studio is using a version of python I already had installed in c:\Python27, could that be causing a problem?
Someone mentioned in a link I found that they had to copy the 'django' folder to the project folder, but I don't know where that would be. I don't even know what the error means really unless there's a missing package (like dll or assembly in .NET?), but I don't know what paths python would use to try to find a package or even what one would look like.
I see there's a PYTHONPATH environment variable that I don't have declared, should I declare that? Should it point to the C:\Python27 directory?
First, do you have checked your "Python Environment" in your project folder? It may seems like...
Here you may find your django with version. If you dont find it then compile setup.py from django folder again with desire python version. And then right click on "Python Environments" from your project and click on "Add/Remove Python Environments" to select python version.
Ok with a lot of fooling around I found this directory:
%LOCALAPPDATA%\Microsoft\Web Platform Installer\installers\PythonDetectInstalls
In a mangled sub-folder there is a powershell script DetectPythonInistalls.ps1 that has these two lines for checking if python is installed already:
$regKey = "hklm:SOFTWARE\Python\PythonCore\$pythonVersion\InstallPath";
$correctRegKey = "hklm:SOFTWARE\Wow6432Node\Python\PythonCore\$pythonVersion\InstallPath";
Uninstalling all my pythons did not remove these keys. After removing these registry keys with regedit, WPI allowed me to install its own version of python 2.7 and all the other goodies to go with the Windows Azure Python SDK and it worked.