0

I'm trying to import three modules that I've installed with pip: requests, bs4, and pillow. I'm installing them from the command line, but I'm attempting to import them from both the command line and Anaconda. The problem is that bs4 and pillow are unavailable from the command line, and pillow is unavailable from within Anaconda

# installing bs4 (other installations have been omitted for brevity)
PS C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib> pip install bs4
Processing c:\users\xxxx\appdata\local\pip\cache\wheels\0a\9e\ba\20e5bbc1afef3a491f0b3bb74d508f99403aabe76eda2167ca\bs4-0.0.1-py3-none-any.whl
Requirement already satisfied: beautifulsoup4 in c:\users\xxxx\anaconda3\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\users\xxxx\anaconda3\lib\site-packages (from beautifulsoup4->bs4) (1.9.5)
Installing collected packages: bs4
Successfully installed bs4-0.0.1

# verifying that requests, bs4, and pillow are in the list of installed modules
PS C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib> pip list | Select-string "requests|bs4|pillow"

bs4                                0.0.1
Pillow                             7.2.0
requests                           2.24.0


PS C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib>

# starting Python and trying to import the module
PS C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib> py
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> import bs4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
>>> import pillow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pillow'

I noticed that my packages keep installing in C:\users\xxxx\anaconda3\lib\site-packages, but the problem seems to be that they need to install in the C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib directory. I was able to copy the folder that contains the "requests" module over to C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib, and now I can import it from the command line and from within Anaconda.

However, after installing bs4 and pillow, bs4 can be imported from Anaconda but not imported on the command line and pillow cannot be imported from Anaconda or the command line.

I have already tried pip3, but I get an error saying that that is not a recognized command. I have tried uninstalling bs4 and pillow, running $PYTHONPATH = "C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib", and reinstalling the modules. I got a message saying that the requirements for bs4 were already satisfied, and it said that it installed pillow. Still, neither are available from the command line

UPDATE: I repaired Python, and now I can import bs4, but I still cannot import pillow from the command line or from within Anaconda. Also, when I type out "python" into the command line instead of just "py", I get this warning message:

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

When I try to activate my conda environment, per the website in the warning message, I don't get any errors in the activation process, but the warning message persists:

PS C:\Users\xxxx> conda info --envs
# conda environments:
#
base                  *  C:\Users\xxxx\Anaconda3

PS C:\Users\xxxx> conda activate base
PS C:\Users\xxxx> python
Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>>
Ethan
  • 53
  • 1
  • 12
  • 1
    You may wish to see: https://stackoverflow.com/questions/44528638/after-pip-successful-installed-modulenotfounderror – Joshua Foo Jul 17 '20 at 01:16
  • Make sure that both folders are in your `PYTHONPATH` environment variable. – NotAName Jul 17 '20 at 01:17
  • 1
    Does this answer your question? [after pip successful installed: ModuleNotFoundError](https://stackoverflow.com/questions/44528638/after-pip-successful-installed-modulenotfounderror) – Joshua Foo Jul 17 '20 at 01:17
  • 1
    See also: https://stackoverflow.com/questions/32680081/importerror-after-successful-pip-installation/32680082 – cel Jul 17 '20 at 08:41
  • Thanks for the suggestions. I tried pip3 before creating the post, and I just tried it again, but it's an unrecognized command. I also tried uninstalling bs4 and pillow, then issuing`$PYTHONPATH = "C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib"` before reinstalling the modules. It told me that bs4 was already installed, and it installed pillow, but I could not import it at the command line – Ethan Jul 17 '20 at 11:29
  • That's incorrect in a number of ways. In Bash, no dollar sign before the variable, and no spaces around the equals sign. In Windows, the command is `set`, and it doesn't take a dollar sign or any equals sign at all. – tripleee Jul 17 '20 at 12:00
  • @tripleee, PS is supports various syntaxes. After running `$PYTHONPATH = "C:\Users\xxxx\AppData\Local\Programs\Python\Python38\Lib"`, I echoed it and it was set correctly. I set it to an incorrect path using `set` as suggested, then I set it back to the correct path using the supposedly unsupported syntax, echoed it, and it had been changed back to the correct value – Ethan Jul 17 '20 at 12:35
  • I checked all of those questions above and this is not a duplicate – Ethan Jul 20 '20 at 19:50

0 Answers0