Using command line in Jupyter Notebook not executing commands in virtual environment

Viewed 44

I need to use the command line in Jupyter Notebook in a virtual environment, but the commands don't execute in the environment itself. I'm using Anaconda Navigator to open Jupyter Notebook. For background, I use a Mac.

Whenever I do something like ! pip install xyz, it installs the package in the Anaconda directory for libraries (see the image). I made sure that the kernel is in the environment, so that's not the problem.

What's interesting is that if I try to import a package, I can only import packages from the environment itself, not the Anaconda libraries. In other words, installing packages doesn't occur in the environment, but importing packages does.

Image that shows the pip install

This wouldn't matter that much because I could download packages in the Terminal itself, but I also need to do things like in the image below in my virtual environment, which is not possible to do in the Terminal (or is it?).

Example of what I need to do

Any ideas on how to fix this?

EDIT: That error is fixed. However, I'm getting an error if I try to use a Python command: image of error. The first line just defines the file path for the script (the last item in the list is a .py file). I tried doing "%%python" followed by the command, but it doesn't work. Any ideas?

0 Answers
Related