I am trying to run the following code in python 3.7 using spyder
import numpy as np
import freud
from util import box_2d_to_points
import matplotlib.pyplot as plt
data_path = "data/phi065"
box_data = np.load("{}/box_data.npy".format(data_path))
pos_data = np.load("{}/pos_data.npy".format(data_path))
def plot_rdf(box_arr, points_arr, prop, rmax=10, dr=0.1, label=None, ax=None):
"""Helper function for plotting RDFs."""
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=(12, 8))
ax.set_title(prop, fontsize=16)
rdf = freud.density.RDF(rmax, dr)
for box, points in zip(box_arr, points_arr):
rdf.accumulate(box, points)
if label is not None:
ax.plot(rdf.R, getattr(rdf, prop), label=label)
ax.legend()
else:
ax.plot(rdf.R, getattr(rdf, prop))
return ax
First installed a package called "freud" (pip install freud
)
then when I run i get this error,
ImportError: cannot import name 'box_2d_to_points' from 'util' (/opt/anaconda3/lib/python3.7/site-packages/util/__init__.cpython-37m-darwin.so)
So I checked to see if package is installed by using
pip show util
I got this: WARNING: Package(s) not found: util Note: you may need to restart the kernel to use updated packages.
and yes i did restart the kernel, nothing changed.
When i try to install it
pip install util
ERROR: Could not find a version that satisfies the requirement util (from versions: none) ERROR: No matching distribution found for util Note: you may need to restart the kernel to use updated packages.
I searched online and found that it can be installed as pip install python-utils
but then it creates a different directory and the code doesn't compile even if i change to from python_utils import box_2d_to_points
.
But I think it is some directory issue that the package cannot be read. If you look into the screenshot attached, in library with folder 'freud' there is a folder 'util' that has the file "init.cpython-37m-darwin.so" I am wondering how to install this package. I followed the solutions in (Install a Python package into a different directory using pip?) but still didn't solve the problem.
The documentation for freud package can be found here:
and here is a screen shot of directories
Thank you in advance,