I am having trouble getting PyDev on Eclipse to recognize installed modules (gensim), which work fine in IDLE. I am using Windows Vista, 32-bit. Python 2.7.
I have found this question asked: here, here, here, and here.
The recommended solution is to go to preferences > pydev > interpreter - python, and remove and re-add (w/ Auto Config) the python interpreter. I have done this, and have restarted Eclipse. In PYTHONPATH, C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg, appears, but I still run into the import error. My code is:
from gensim import corpora, models, similarities
And this yields:
Traceback (most recent call last):
File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
from gensim import corpora, models, similarities
File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
from gensim import corpora, models, similarities
ImportError: cannot import name corpora
Another recommended solution is to manually add the folder by clicking "New Folder" in the bottom part of the interpreter - python screen and navigating to the location where gensim installed. I have also done this, and added C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg\gensim, which has all the necessary \__init__.py files. But, I still get the ImportError.
Any suggestions for what else I could try?
This is independent of Eclipse/PyDev. You'll get the same error running the code in any other way. Your module imports gensim. The first entry on the PYTHONPATH is the current directory, and your module is called gensim.py, so your module attempts to import iteself. Because imports are cached, you don't get into infinite recursion but get a reference to a module containing... nothing, especially not the things you expected from the "real" gensim module.
The error message should mention this possibility, it's incredibly common. The solution is to rename your file.
Related
I am trying to modify an AI for a game on the steam store. The AI communicates through the game with the use of a mod called the communication mod. The AI is made using a python project. The package I am trying to modify is https://github.com/ForgottenArbiter/spirecomm and the mod is https://github.com/ForgottenArbiter/CommunicationMod.
I want to add the pandas package and the job lib package as imports so I can use a model I have made for the AI. When I try to run the game + mod after adding the pandas and joblib packages as imports I get this error in the error log.
Traceback (most recent call last):
File "/Users/ross/downloads/spirecomm-master/main.py", line 6, in <module>
from spirecomm.ai.agent import SimpleAgent
File "/Users/ross/Downloads/spirecomm-master/spirecomm/ai/agent.py", line 10, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
This issue only happens when the game is running and the mod tries to run. if I just run the file in terminal it is able to compile/run and send the ready signal
I have checked that I have these modules installed and it is installed. I am on an M1 Mac and I have several different versions of python installed but I have checked them all and it is installed for each of them. I have also opened the python package using pycharm and added pandas and joblib to the python interpreter as a package.
Another thing I have tried is modifying the setup.py file to say that pandas and joblib are required. I then ran it again but I am not sure if this had any effect because I have already run it before.
There is limited help that can be provided without knowing the framework that you are is using but hopefully this will give you some starting points to help.
If you are getting a "No module named 'pandas'" error, it is because you have imported pandas in your code but your python interpreter cannot find it. There are two major reasons this will happen, either it is not installed (which you say has definitely happened) or it is not in the location the interpreter expects (most likely).
The first thing you can do is make sure the pandas install is in the PYTHONPATH. To do this look at Permanently add a directory to PYTHONPATH?.
Secondly, you say you have several versions of python and have installed the module for all versions but you most likely have several instances of at least one version. Many IDEs, such as PyCharm, create a virtual environment when you create a new project and place in it a new instance of python interpreter, or more accurately a link to one version of python. Within this virtual environment, the IDE then loads the modules it has been told to load and thus makes them available for import to the code using that particular environment.
In your case I suspect you may be using a virtual environment that has not had pandas loaded into it. You need to investigate your IDEs documentation if you do not know how to load it. Alternatively you can instruct the IDE to use a different virtual environment (one that does have pandas loaded) - again search documentation for how to do this.
Finally, if all else fails, you can specifically tell your code where to look for the module using the sys.path.append command in your code.
import sys
sys.path.append('/your/pandas/module/path')
import pandas
I can't import modules of any kind. I know that I have the modules installed, and that they are inputted correctly, but it still does not work, and gives me this full error when trying to import numpy as np:
C:\Users\alecd\Desktop\Code\PYTHON\chess>C:/Users/alecd/AppData/Local/Microsoft/WindowsApps/python.exe c:/Users/alecd/Desktop/Code/PYTHON/chess/chess_board.py
Traceback (most recent call last):
File "c:/Users/alecd/Desktop/Code/PYTHON/chess/chess_board.py", line 3, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I keep all my code in a lot of folders, and when I take the code out of the folders it works. However I don't want all of my code to be in one massive folder. I tried creating a new PYTHONPATH, which I believe will work but I would have to append all of my scripts every time, which would be pretty inefficient.
I actually had the same problem a week ago and found out that I installed 2 python envs at once. One was from original website(python.org) the other was from Microsoft Store. I kept installing modules on one and using another to run my code.
If you are using some kind of text editor(I was using Visual Studio Code) you need to select the right environment for compiler.
On Visual Studio Code you change compiler from left-bottom corner
VSCode
I'm getting the error
Traceback (most recent call last):
File "ghs.py", line 1, in <module>
import stdio
ImportError: No module named stdio
When I try to run my script. I can run my script on other machines just fine. I have installed python using homebrew. And I've tried everything I can think of to get it to recognize my modules! I've uninstalled and reinstalled using brew. I've tried changing the path (though I don't fully understand this). I get no issues using brew doctor.
I've also tried using a python virtual environment but to no avail.
Any ideas on how to fix this issue or else 'start fresh' from a fresh version of python?
When you import a module, Python looks for it at the directory your code is, and the directory in which the built-in libraries are (C:\Users\pc\AppData\Local\Programs\Python\Python35-32\Lib in my case, I'm using Windows 10 and Python 3.5). If it can't find it, it raises ImportError.
I couldn't find a module named stdio in my computer. I also know some C++ and as far as I know, stdio is the library for inputs and outputs(prints). In python, there is no need to import such a library.
You can use try,except statement to test if your code works without importing the module like this.
try:
import stdio
except:
#rest of your code goes here
You will need to indent your whole code however this can be done easily with a text editor in which you can edit more than one line at a time.
Whenever I try to import a file into python, it comes up with this error(or similar):
Traceback (most recent call last):
File "C:/Python33/My Files/username save.py", line 1, in <module>
import keyring.py
ImportError: No module named 'keyring'
I am trying to create a password storing program, and I was looking up for good ways to keep passwords secure, and someone said use import keyring, so I did, except, it never works. I must be doing something wrong, but whenever I look anything up for python, it never works out for me. It's almost as if loads have things have been changed over the years.
and idea's?
The keyring module is not part of the Python standard library. You need to install it first. Installation instructions are included.
Once installed, use import keyring, not import keyring.py; the latter means import the py module from the keyring package. Python imports should use just the name of the module, so not the filename with extension. Python can import code from more than just .py python files.
I was getting the same error "ModuleNotFoundError: No module named 'keyring'". And after installing this module pip install keyring, the same error occured with another module name. Then I came to the conclusion that it is the fact that the VSCode is not able to connect to my venv, even after setting the Python Itereptor. Press CTRL + SHIFT + P, and then type Python: Select Interceptor, and select your venv, if you want to set this.
To fix the issue, I had to force the VSCode to use the .venv I created, and luckily there is a dropdown to do that, on the top right corner as in the preceeding image. Click ont the Python version, and then you will be able to select your virtual environment.
Now it will take the modules from your virtual environment.
I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly in Ninja.
First I was only getting the message No module named ____. I checked sys.path and found that the path was within the application
/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7 was a typical path. I tried changing the path,but it doesn't seem to do anything to sys.path even after restarting the ide.
But I wanted the path to refer to where the modules are stored (which is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). I was able to get numpy and scipy to work as well as parts of mpl_toolkits by adding the contents of my path to the folders that sys.path gave. However, I still can't get fully functioning modules within the ninja ide interpreter. I'll give some examples below of what happens when I import certain modules.
import matplotlib.pyplot
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
import mpl_toolkits
from mpl_toolkits.mplot3d import axes3d
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 14, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
Thanks for the help. I apologize, I am very new to programming, but I did put in about a day and a half of research before posting here.
That's strange as the sysconfig module is a part of Python 2.7 standard library.
Are you sure that Ninja is using the right Python version? Try running:
import sys
print sys.version_info
from Ninja, to see which Python version it is actually using.
I know this question is a few months old, but I wanted to post my solution in case others find it useful. I had a very similar problem, and had a lot of trouble finding a quick workable solution anywhere.
My somewhat roundabout solution was to simply create a virtualenv folder with the version of numpy I wanted, and then pointed the "virtualenv" property for NinjaIDE project to that folder. I restarted NinjaIDE and boom, instantly worked.
To set the virtualenv property for your project via the GUI, go to the Project menu:
Project > Open Project Properties > Project Execution,
and you should see a variable called "Virtualenv Folder". Point that to the folder for your virtualenv, and it should work. (May need to restart NinjaIDE.) This worked for me, NinjaIDE version 2.2 under Ubuntu 12.04.
One quick note: I actually didn't use virtualenv exactly -- I had to use a "conda env," since I am using the Anaconda distribution, and apparently it is not well-tested with virtualenv yet. (I actually got a warning when I went to easy_install virtualenv. Hadn't seen that before.)
Either way, this stackoverflow question has some nice pointers to virtualenv tutorials: Comprehensive beginner's virtualenv tutorial?
Good luck!
I was having a similar problem trying to import a module from /home/paul/lib/python using the console of the Ninja-IDE. I found out that /home/paul/lib/python didn't appear in syspath when checking in the console of the Ninja-IDE. But it did in the terminal!
By starting the Ninja-IDE from the terminal, /home/paul/lib/python was in syspath when checking in the console of the Ninja-IDE. I was now able to import the module I needed.
I hope this might be of some help. If not to ebris1 than maybe to others.