I recently downloaded and installed feedparser with python,
I tried to run it but Netbeans shouts on import:
ImportError: No module named feedparser
restarted the Netbeans, still no go.
Netbeans by default uses Jython,
if you go to Tools>Python Platforms and see that Jython is the default.
Switch it to Python and so the installed libraries would work.
If you already have a project, you should right click on it, choose Python and on the platform choose Python instead of Jython.
You might need to set the PYTHONPATH environment variable to include the install path of feedparser. Just a guess, but this has fixed this issue in the past for me.
Related
I am using PyCharm to develop a python project, which uses an external library called win10toast. I have installed win10toast using PyCharm. However, when I tried to run the .py file using cmd (i.e Externally running the python file), an error shows up:
ModuleNotFoundError: No module named 'win10toast'.
I have python 3.6.4. I installed win10toast using PyCharm.
from win10toast import ToastNotifier
I expect the program to run without any error, but currently I am getting the ModuleNotFound error.
Python can be tricky to run properly because it is sensitive to where you installed your dependencies (such as external libraries and packages). If you installed Python to one directory, but accidentally installed the external library to another directory, when you run your .py program, it will be unable to call from the external library because it doesn't exist in the same library that Python is running from.
Lookup where you installed Python on your computer and then find where you installed the external library. Once your find where you installed the external library, move its entire package content to the same directory where Python is installed. Or better yet, reinstall the external library with pip into the same directory as Python.
If you're on Mac, Python and its related dependencies are usually stored somewhere in /User/bin. If you're on Windows, it will be stored somewhere in your C:// directory (possibly somewhere in C:\Users\username\Local\AppData). If you're on Linux, it will be stored somewhere in /usr/bin. Whatever you do, don't move Python from wherever it is because sometimes that can mess up your system for certain operating systems like Mac, which comes with its own version of Python (Python 2.7 I believe, which is outdated anyway).
Lastly, you may have two different versions of Python on your computer, which is common; Python 2.7 and Python 3+. If you wrote your program in one version, but ran it from the other, the external library can only be called from whichever Python version you installed it to. Try running your .py program with python3 instead of python (or vice versa) and see what happens. If it works with one python version over the other, that tells you that the external library is installed in the other version's directory.
That should solve your issue.
I would suggest that you not use PyCharm to install packages, at least not
if the result deviates in the slightest from doing a "pip install" at the command line. I see no reason to involve PyCharm in configuring Python installations. It's just asking for trouble.
I admit that I'm not familiar with the practice I'm suggesting you avoid. I've been using PyCharm since pretty much the week it came out (was an avid user of the IntelliJ Python plugin before that), and have never once considered doing anything but installing Python modules at the command line. That way, I'm sure right where those modules are going (into which base Python install or venv). Also, I know I'm doing all that I can to minimize the differences that I might see between running code in PyCharm and running it at the command line. I'm making my suggestion based solely on this practice having never gone wrong for me.
I have multiple base Python versions installed, and dozens of venvs defined on top of those. PyCharm is great at allowing me to indicate which of these I want to apply to any project or Run/Debug configuration, and utilizing them seamlessly. But agin, I administer these environments at the command line exclusively.
I still experience issues in switching between the command line and PyCharm in terms of one module referencing others in a single source tree. My company has come up with a simple solution to this that insures that all of our Python scripts still run when moving away from PyCharm and its logic for maintaining the Python Path within a project. I've explained the mechanism before on S.O. I'd be happy to find that if anyone is interested.
The library win10toast installed in the directory: YOUR_PYCHARM_WORKSPACE\PycharmProjects\YOUR_PROJECT_NAME\venv\Lib\site-packages
but when you are running your program using cmd, pycharm interpreter uses site-packages directory that you installed python at there. for Ex: C:\Python27\Lib\site-packages
So, you can install the win10toast library to this windows directory using pip.
I am fairly new to Python and trying to install the Pillow package on Windows 7. I downloaded and ran the MS Windows installer Pillow-2.2.1.win-amd64-py3.3.exe from here. It appeared to install fine. If I run the simple line of code:
from PIL import Image
directly from the Python interpreter, it runs fine. A help() on PIL gives me the package contents.
But when I try to run the same line of code from within a script, I get an ImportError: No module named PIL. What am I missing?
(Note that I've been able to import sys and import MySQLdb from within scripts just fine.)
Resolved: sure, enough, I'm running Python 2.7 when I run scripts. (I think I vaguely recall having to install an older version so I could interface with MySQL.) Thank you all for pointing out that I should check the version being used.
For third-party modules for Windows, my go-to resource is Christoph Gohlke's Python Extension Packages for Windows. You can find the latest version of Pillow here. Make sure you're working with the python.org version of Python.
As far as your specific error, it's hard to tell exactly without a traceback, but make sure your script is calling the correct version of Python. If you have also installed Python 2.7, for example, your script may be calling that instead of 3.3.
In such cases I'm simply printing the sys.path at the beginning of the script in trouble and comparing it with the one from the working python interpreter. In most cases I was running the script with a different python interpreter.
In my case , I was referring to wrong pip folder.
Changed virtual environment in pycharm to point to right pip folder to solve this issue
import sys
print ( sys.path )
I am new to python and Canopy. I have searched for the possible solutions online, including the support forum of Enthought Canopy, but failed to solve my problem by following the instructions under other similar questions.
I use Mac OS, and wanted to install external python packages to my Enthought Canopy (specifically, a new package named "ggplot" (https://github.com/yhat/ggplot/)).
The instructions on the support forum of Enthought (https://support.enthought.com/entries/23389761-Installing-packages-into-Canopy-Python-from-the-command-line) said " follow standard Python installation procedures from the OS command line ". However, I could only install this package to my previous python library (system default python). When I want to import this module in Canopy, it failed. I thought I might need to change the installation path in order to install this package in Canopy, but not sure how to change and where to change.
When I want to use Sublime text to run my scripts when I set Enthought as default python env, it succeeded so I guess it still imported the package from my previous python library. How can I know which environment the editor is currently using?
Thanks!
1) The cited article links to another article, which describes how to make Canopy Python be the default python, and states that the easiest way is simply to use the Canopy Preferences dialog to make Canopy be your default Python.
If you prefer not to do that, the article suggests that you modify the PATH environment variable (note that this is not actually an "installation path" but a more general path used for locating programs to run for any reason.)
So I'm guessing that you don't know how to do this? Here's a simple way. From a terminal, type the following (substituting your own user name) before continuing with the installation:
export PATH=/Users/your-user-name/Library/Enthought/Canopy_64bit/User/bin:${PATH}
2) To find out what environment your editor is using, run the following program:
import sys
print sys.prefix
I am trying to work with Python 2.7 in eclipse on my Mac, I don't belive that I have ever messed with the source files, but when I try to import urllib, urllib2 or random it tells me that it can't find them. I used the eclipse autoconfig-ed 2.7 interpreter so I have no idea what happened to the modules. How can I find it so that I can include it?
Please check that Eclipse has the right PYTHONPATH environmental variables. Open a python interactive interpreter in a shell and try importing the same urllib, urllib2 and random modules. If that works, then Eclipse might be configured wrong. If you can't access those modules, then you should consider fixing your PYTHONPATH.
I recently downloaded the python-ogre SDK, which appears to include its own python interpreter.
I say "appears" because this interpreter also seems to depend on the standard python 2.7.2 installation. I tried uninstalling the latter, and the python-ogre SDK interpreter complains that python27.dll is missing from my computers.
I really don't understand how the two interpreters are related, and the python-ogre SDK forum topic has been less than helpful.
I really need to instally PyYAML such that the python-ogre interpreter has access to it. I successfully installed PyYAML (the installer detected python 2.7) and the standard python console manages to import it without any issues.
The python-ogre SDK interpreter, however, complains that there is no module by that name.
I'm completely lost. Can someone point me in the right direction and/or explain what is going on?
With many thanks in advance,
Blz
EDIT
MichaelMior hinted at the possibility that this involved my sys.path. I'm rather new to python, so any explanations are welcome.
The output of sys.path for the standard python installation is:
C:\Windows\system32\python27.zip
C:\Python27\lib\site-packages\pip-1.0.2-py.2.7.egg
C:\Python27\DLLs
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
The output of the python-ogre SDK is:
C:\Windows\system32\python27.zip
C:\python-ogre\[SDK]\DLLs
C:\python-ogre\[SDK]\lib
C:\python-ogre\[SDK]\lib\plat-win
C:\python-ogre\[SDK]\lib\lib-tk
C:\python-ogre\[SDK]
C:\python-ogre\[SDK]\lib\site-packages
EDIT 2:
Okay I got it! I just did sys.path.append('C:\Python27\lib\site-packages')
Apparently, 3rd party modules get installed to that directory. Is this safe to do? Do I risk creating any sort of conflicts?
Each Python interpreter has its sys.path, which it will use to search for modules.
When you installed PyYAML, it got installed to the directory for the plain Python interpreter (C:\Python27\lib\site-packages). When you try to import it from python-ogre, it has no idea to look there so it can't find it. That's what adding the folder to sys.path did - tell python-ogre to look in that folder for modules.