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.
Related
I'm now trying to run qiskit visualization functions(e.g. .draw() methods) in vscode.
I use latest version of Python, 3.11.1, and followed Getting Started Qiskit in here.
Also I installed qiskit extension in vscode.
However, when I run a qiskit code, the visualization functions don't work, even though code is compiled successfully.
I checked visualizing modules(mathplotlib, etc.) were installed.
I tried to re-install Python and vscode, including downgrading Python to 3.8. And it didn't work.
Additionally, qiskit-chemistry and qiskit-aqua installation warnings are pop-upped, but installation doesn't work.
I really don't know it is related on this problem, but I think maybe it's not since qiskit-aqua is deprecated.
The following screenshot is result of the qiskit test code.
result of running
draw() and plot_histogram() doesn't work as you can see.
How can I fix this problem?
These functions are meant to be used in Python Notebooks - they won't show up in normal .py files. Try using VSCode's Jupyter Notebook (.ipynb files) feature instead.
I have installed pythonnet to use clr package for a specific API, which only works with clr in python. Although in my python script (using command or regular .py files) it works without any issues, in jupyter notebook, import clr gives this error, ModuleNotFoundError: No module named 'clr'. Any idea how to address this issue?
Here is simple suggestion: compare sys.path in both cases and see the differences. Your ipython kernel in jupyter is probably searching in different directories than in normal python process.
since you are intended to use clr in jupyter, in jupyter cell, you could also
!pip install pythonnet for the first time and every later time if the vm is frequently nuked
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.
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
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.