Just downloaded TextMate, can't import modules - python

I am trying to use python in order to simulate social networks, this requires matplotlib.pyplot, networkx and xlrd. Everything works fine from terminal, IDLE or X11 but when I try to use TextMate import matplotlib.pyplot as plt and import xlrd throws up ImportError: No module named... however import networkx works fine!
I downloaded python via EPD and so matplotlib came ready baked in however I got xlrd and networkx with easy_install.
Anybody have an idea what might be going on?

You need to tell TextMate which Python to use. One way to do that is to define the shell variable TM_PYTHON with an absolute path to the Python interpreter you want to use. In the TextMate menu, select Preferences, then the Advanced tab, then the Shell Variables tab, and click + to add the new variable. If you don't know the absolute path to the EPD Python, type which python (or whatever you are using to start Python) in a Terminal shell window.

Related

How do I import Pandas library into PyCharm?

I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error : ModuleNotFoundError: No module named 'pandas'
I have tried to uninstall and install again many times but nothing seems to work. Does anybody know a solution to this?
You can try downloading the library from PyCharm settings:
File -> Settings
then, Project: -> Python Interpreter
Click a + sign to the right,
Search for the pandas library,
and finally, press 'Install Package'
I think you have to choose the right python interpreter. Check my screenshot
You likely have multiple copies of Python installed on your system. PyCharm can be configured to use any version of Python on your system, including any virtual environments you've defined. The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code.
There are two places where you specify a Python version. First of all, your Project has a version associated with it. Check the "Python Interpreter" section of the "Project" section of your Preferences for that. That version is used for syntax highlighting, code completion, etc.
By default, the abovementioned Python version will also be used to run your code. But you can change the version of Python that your code is run with by creating or modifying a Run Configuration. To do this, check the menu next to the Run and Debug toolbar buttons near the top-left of your PyCharm window.
When you do get into the Python Interpreter section of the Preferences, you'll find that you can see all of the modules installed for each Python version that PyCharm knows about. You can use this to check to see if Pandas is installed for a particular Python version.
I would suggest you get comfortable with all that I've said above. It will save you many headaches in the future.

PyCharm on MAC - ModuleNotFoundError: No module named 'sklearn'

I'm using PyCharm and learning the basics of Machine Learning through a Mooc.
As always, things don't go as expected when you try things shown by the teacher by yourself and until now I was able to fix the issues by myself but I'm stuck since quite a while and that's why I created an account here :)
when I try import sklearn as pd (can't find how to do this as "code") I get ModuleNotFoundError: No module named 'sklearn'
I've had the same issue with pandas and numpy previously and was able to solve it by adding
import sys
sys.path.append("numpy_path/pandas_path")
and trying some things on the terminal (I'm on Mac) like pip install numpy or conda install numpy but this time nothing seems to work.
I suspect the issue to be that sklearn is somewhere else on my computer than where the Python program is searching but am not sure.. Let me know if you can help :)
It may be that Pycharm is using a different interpreter environment than you were using before. Best way to check is in Pycharm go to Pycharm on the menu, then preferences, then under 'Project' choose 'Project Interpreter'. At the top a dropdown will show you what environment Pycharm is using for this project. Underneath will be all the libraries you have installed in that environment. You can look down the list and check if the libraries you want are installed. If they aren't hit the + button underneath, search for the libraries, select and hit install.
Also a note. It's odd that you are choosing to import sklearn as pd as that is not the convention. The convention is to import pandas as pd. Technically it is not incorrect, the interpreter will accept it, but it is not the convention.

Python's matplotlib import

On my working PC (Windows7, no internet connection) there are two Pythons: one is the main (C:\Python36-32) with IDLE. Another - freshly installed Anaconda (C:\ProgramData\Anaconda3) - just for scipy and matplotlib (IT guy thought it is the best option).
So, matplotlib works only if I run my scripts from cmd. But it is not comfortable. I prefer IDLE or any other modern environment.
But if I try use matplotlib in IDLE - I got an "No module named 'matplotlib'". I tried to edit sys.path and run:
sys.path.append("C:\\ProgramData\\Anaconda3\\Lib\\site-packages").
It helps a little bit - I got new error "No module named 'matplotlib._path'". So, it looks like IDLE knows what is matplotlib now, but doesn't know it's functions.
Is there any way to connect IDLE with Anaconda's libraries? Maybe to append paths recursively?
It's probably not a good idea to mix the python distributions through the system path.
Python should ship with IDLE. So you can use the IDLE from the Anaconda distribution,
C:\ProgramData\Anaconda3>python.exe Lib\idlelib\idle.py
Also note that Anaconda should also provide Spyder. This might be a nicer IDE.

Using Anaconda modules outside of IPython

I'm interested in creating physics simulations with Python so I decided to download Anaconda. Inside of an IPython notebook I can use the pylab module to plot functions, for example, with ease. However, if I try to import pylab in a script outside of IPython, it won't work; Python claims that the pylab module doesn't exist.
So how can I use Anaconda's modules outside of IPython?
I bet it will work if you use Anaconda's Python distribution.
Try running ./anaconda/bin/python and importing it from that Python session.
As a side note,
If you want to keep this functionality and move to a more script-like environment I would suggest using something like Spyder IDE. It comes with an editor linked with the IPython console that supports all the same magics as the IPython notebook.

python newbie: importing numpy module in eclipse

I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.
So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the
import numpy
import pylab
disappeared so I understood that the reference to that module is ok.
Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).
Can anyone tell what should I do to run this code?
my interpreter setting on eclipse:
If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.
Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *
Edit:
Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.
I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.
I first tried adding a reference to the site-libraries at:
C:\Anaconda3\Lib\site-packages
And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:
C:\Users\myname\AppData\Local\Programs\Python\Python35-32
However, Anacondas installed another version somewhere else. By going into:
Windows > Preferences > PyDev > Interpreters > Python Interpreter
and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.
Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.
Simply removed the old numpy and installed version 6. located here
Another way to circumvent this problem is to use pip install numpy check how to install pip

Categories

Resources