0

Below is my file setup:

|-Desktop

|--Python Projects

|---Senior Project

|----pyspectra-master

|-----pyspectra-master

|------pyspectra

My goal is to import libraries from pyspectra into Jupyter Notebook. I get a ModuleNotFoundError when I type this code:

from pyspectra.readers.read_spc import read_spc 

I am unsure why this happens. I also get an error for this code:

from pyspectra_master import pyspectra 

How am I supposed to call pyspectra-master with a dash? It does not seem possible.

Is there an easier way to import modules into python? I saw it possible to import modules directly from Github.


Macgyver notes on creating virtual environment manually:

Create virtual environment for Linux:

python3 -m venv --system-site-packages /opt/venv01 cd /opt/venv01 source /opt/venv01/bin/activate pip install openpyxl==3.0.7 pip install pyspectra 

... if multiple python installs exist, make sure to put the full path of the python.exe file here instead of the default.

/path_of_python/python3.exe -m venv --system-site-packages /opt/venv01 

Create virtual environment for Windows:

  • Manually install Python for Windows with https://www.python.org/downloads/
  • Git Bash can be used like the command line in Linux, but in Windows
  • You will need to make sure Python is appended to the PATH environment variable in Windows so the command line has access to the Python tools. This should get added automatically with the Windows Python install
  • repeat Linux commands above, but use Windows folders instead; I believe the C: drive looks like /c/ in GitBash for Windows.
  • Once your virtual environment is set up, install Virtual Studio Code and open your source code folder (virtual environment folder). This is typically the same folder where you check out github source code. That way everything is isolated. The venv folder is usually called whatever git branch or version you're working on and is checked out from.
  • Configure the virtual environment to be active in Visual Studio Code IDE so you can run your application using the IDE tools instead of the command line. Then you can debug your source code using the IDE as well by placing breakpoints.
14
  • docs.python.org/3/tutorial/modules.html#the-module-search-path Commented Mar 23, 2023 at 7:53
  • If you write a quick program with two lines .. import sys ... print(sys.path) ... what do you get? Now add import pyspectra. What do you get for the print then? Commented Mar 23, 2023 at 7:54
  • Also, my next recommendation is to read about modules versus packages in Python. The files don't always need to have the same name. Then run this code. stackoverflow.com/questions/37752054/… Commented Mar 23, 2023 at 8:03
  • @MacGyver Thank you for the reference. I read through the files and I still am uanble to understand why there is an error. Commented Mar 24, 2023 at 0:58
  • @MacGyver I typed sys.path and got a list of directories leading out of Anaconda3. I also got a directory leading to my senior project folder. I cannot import pyspectra. I also am not able to import with github, even though I installed git Commented Mar 24, 2023 at 1:08

1 Answer 1

1

Open IPython in Anaconda and type this:

conda install git pip 

Go to Jupyter Notebook and type this:

%pip install git+https://github.com/fujiisoup/pyspectra.git 

Pyspectra can be imported after this.

Sign up to request clarification or add additional context in comments.

3 Comments

Nice work with this!
You should be suggesting and using to use the %pip install magic inside Jupyter notebooks for best experience, dlnvss. While it worked here because fortunately the user's system was set up in a compatible way, use of the exclamation point with install commands can sometimes cause issues and so a magic version was added. See the second paragraph here for more on why use of the exclamation point inside a Jupyter notebook with pip install commands can cause issues. ...
<continued> See here for more about the modern magic install commands that insure installation occurs in the environment backing the kernel underlying the active notebook.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.