You will have a choice of 32 bit or 64 bit. In order to use pyVisa, you need to install the same bitness of VISA and Anaconda. On my PC I used 64 bit for both. The recommended visa is from National Instruments, but other visa suppliers can be made to work... (I use NI Visa, so I have not tried anything else...)
During Installation:
C:\Anaconda3
as the install path. (No spaces in the path)Open a command window in the current folder
Add Conda-Forge as a lower priority channel. This channel has some additional libraries that we will be using.
conda config --append channels conda-forge
Then install the packages that we need:
conda install pyinstaller (useful for distribution)
conda install pyVisa (to control instruments)
conda install scikit-rf (for network tools)
conda install pyqtgraph
conda list (summary of current installation)
conda install python=3.5 (this is how to downgrade, for example)
Conda keeps track of all installed packages, and also does its best to ensure compatible versions of each package are being used.
Conda is also used to update to the latest version of packages. This is where the various libraries and dependencies are analyzed, and only a compatible mixture of libraries is installed. For example, pyVisa needs python 3.5, so the update will know about this, and will not update python to a higher version.
conda update conda (update the package manager) conda update anaconda (good way to update packages)
Solution for Conda IO Error - Run Conda Prompt as Administrator. This is not the usual windows cmd prompt. You'll find this prompt in the Anaconda group of programs along with the Conda Navigator. Right click on the prompt and click Run as Administrator.
conda install <package> (we used this in the last section)
conda update conda (Run cmd prompt as administrator !!!)
conda update anaconda (Run cmd prompt as administrator !!!)
conda update python (don't do this)
conda update --all (don't do this)
conda info <package>
For completeness, I list these additional commands. But you should not need them.
To add conda-forge as a high priority channel instead of lower priority, use
conda config --get channels (list installed chans)
conda config --add channels <package> (to add a high priority chan
conda config --remove channels <package> (to remove a channel)
Go to this website if you are serious about learning to write Python programs with a GUI
This will guide you for making python programs with a QT based GUI. All the examples can be copied and pasted into a text file (for example, notepad++), named with .pyw extension, and double clicked to run.
The examples just work, so it is a great way to see how things are done.
The GUI is designed directly in the python program, via text commands. So it is an approach that does not need any external files.
It is a good way to prepare for the QT Designer application where the GUI is built by dragging widgets from a pallet and placing them in the window.
Create a text file call hello.py
Copy the following python code into the file and save it
python print("Hello World") # first program input("") # wait for user to press a key
(but you do not want the input("") line here...)
print("Hello World.")
Create a text file call hello inst.py
Copy this into the file and save it
import visa
rm= visa.ResourceManager()
rm.list_resources()
vna = rm.open_resource('TCPIP::192.168.1.6::INSTR')
print(vna.query('*idn?'))
# input("") # if runningin a console
Double click the file to run it.
For more guidance on pyVisa go to http://pyvisa.readthedocs.io/en/stable/
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import numpy as np
import matplotlib.pyplot as plt
import seaborn
from scipy import fft
Fs = 800 # sampling rate
Ts = 1.0/Fs # sampling interval
t = np.arange(0,1,Ts) # time vector
ff = 5 # frequency of the signal
nPulse = int(Fs/20)
y = np.ones(nPulse)
y = np.append(y, np.zeros(Fs-nPulse))
plt.subplot(2,1,1)
plt.plot(t,y,'k-')
plt.xlabel('time')
plt.ylabel('amplitude')
plt.subplot(2,1,2)
n = len(y) # length of the signal
k = np.arange(n)
T = n/Fs
frq = k/T # two sides frequency range
freq = frq[1:int(n/2)] # one side frequency range
Y = np.fft.fft(y)/n # fft computing and normalization
Y = Y[1:int(n/2)]
plt.plot(freq, abs(Y), 'r-')
plt.xlabel('freq (Hz)')
plt.ylabel('|Y(freq)|')
plt.show()
Does that work?
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(0)
dt = 0.01
Fs = 1/dt
t = np.arange(0, 10, dt)
nse = np.random.randn(len(t))
r = np.exp(-t/0.05)
cnse = np.convolve(nse, r)*dt
cnse = cnse[:len(t)]
s = 0.1*np.sin(2*np.pi*t) + cnse
plt.subplot(3, 2, 1)
plt.plot(t, s)
plt.subplot(3, 2, 3)
plt.magnitude_spectrum(s, Fs=Fs)
plt.subplot(3, 2, 4)
plt.magnitude_spectrum(s, Fs=Fs, scale='dB')
plt.subplot(3, 2, 5)
plt.angle_spectrum(s, Fs=Fs)
plt.subplot(3, 2, 6)
plt.phase_spectrum(s, Fs=Fs)
plt.show()