Pip Error "Import Error: No Module Named Site" - python

I am trying to install Scrapy on my computer and it has been a while since I used pip to install any libraries. Whenever I type:
pip install scrapy
into my command prompt on Windows 10 I get the error message:
Import error: No module named site
Doing a search I have found the below link:
ImportError: No module named site on Windows
with a similar issue and gone to Advanced Systems Settings and Enviromental variables, adding PYTHONHOME with C:\Python38 and PYTHONPATH with C:\Python38\Lib and C:\Python38\Scripts to both user and system variables. But I am still getting the same error message.
I have also uninstall Python and Anaconda and reinstalled them.
Does anyone know anything else I can try or any other reason pip may not be working?

You may use this way to install scrapy on your windows machine.
From http://doc.scrapy.org/en/latest/intro/install.html
Platform specific installation notes
Windows
Though it’s possible to install Scrapy on Windows using pip, we recommend you to install Anaconda or Miniconda and use the package from the conda-forge channel, which will avoid most installation issues.
Once you’ve installed Anaconda or Miniconda, install Scrapy with:
conda install -c conda-forge scrapy

I finally have got scrapy installed on my computer and below I outline the things I had to fix and tried for anyone else having similar issues. Please feel free to correct me or inform me of any redundant steps I may include
Thanks to yabberth for answering my question his method now works on my computer, but there were a few other things I had to fix up first to get things working (many of which seem obvious now in hindsight).
Environmental Variables
My environmental variables were not set up properly for a few reasons.
to access environmental variables I just search for "View Advanced System settings" in windows 10, I then click on Environmental variables. Then I see "User Variables" and "System Variables" both of which have a field called path. path is the field I will be modifying so I double click it on both and am presented with a list of paths.
In both I include the path to where my Python is currently installed, which unlike most people for some reason is under C:\Users\MyUsername\AppData\Local\Programs\Python\Python37\
as well as:
C:\Users\cell\AppData\Local\Programs\Python\Python37\Scripts\
But it still wasn't working so:
I currently have Python 3.7 installed, but previously had 3.6 and for some reason the paths for 3.6 were still there (not sure if the uninstall is meant to get rid of them or I was meant to do that). Once I deleted these pip started working again and I could install scrapy
After completing the above two steps I was able to install scrapy using windows command prompt using:
pip install scrapy
or as yabberth suggested on anaconda with
conda install -c conda-forge scrapy

Related

Why doesn't import gym work; however, the command pip install gym was done and executed

I have went to the terminal and used,"pip install gym", and it successfully installed gym . When I go to use the, "import gym," command, I get an error when running the code at that line.
Exception has occurred: ModuleNotFoundError
No module named 'gym'
I have looked at other posts and they all say it should work after ruining,"pip install gym." Although mine successfully installed, it still doesn't work.
You need to verify that you are using the same version of python that you did pip install with. In VS Code, you can select the Python version in the upper right corner. Simply type "python --version" into the console to verify the version. You might want to use Anaconda because someone libraries like Tensorflow only fully-support Anaconda.
if you have pip installed it, there is no way that it will not work. Unless you've installed it to a virtual environment and running your program without it and vice versa. Or you've installed to a different version of python on your system.

Installed selenium with pip, folder is in site-packages, using correct interpreter, but still cannot import (Win10, Python 3.10.9)

I'm trying to use selenium, but can't get python to recognize it.
I installed it first using "pip install selenium" and "pip install webdriver-manager". It is in the folder "C:\Users\{username}\AppData\Local\Programs\Python\Python310\Lib\site-packages\selenium", but I get the error "ModuleNotFoundError: No module named 'selenium'" when I try to import it.(https://i.stack.imgur.com/dVplU.png)
(https://i.stack.imgur.com/wiREJ.png)
Here it is shown as installed with the command "pip list"
(https://i.stack.imgur.com/QhOu7.png)
I also tried uninstalling it and reinstalling with flags that I saw some people say worked, but it didn't make a difference.
(https://i.stack.imgur.com/VTTMU.png)
I only have one python interpreter version installed, 3.10 (so only one python folder, "Python310"). I have pandas in the same site-packages folder which I can import and use no problem.
If anyone knows what the issue might be, please let me know. I can't figure it out for the life of me.
Okay, I solved the issue by completely uninstalling the interpreter which I got from the Microsoft Store and reinstalling it from the official Python website. Now "from selenium import webdriver" works.
Somehow selenium installed in the global scope is not getting recognized within the Virtual Environment of VS Code / PyCharm.
Solution
You need to install Selenium within the Virtual Environment.
Within the Terminal execute the command:
pip install -U selenium

unable to install pymorph

I'm trying to install 'pymorph' on mac os x with 'PIP':
sudo pip install pymorph
I'm getting the following error:
NameError: name 'execfile' is not defined
Command "python setup.py egg_info" failed with error code 1 in
/private/tmp/pip-build-9hjd5tfm/pymorph/
I have read that using a python version different from 2.7 could lead to this kind of problem. Yet, I'm using the 2.7 version:
python --version
Python 2.7.13
Any ideas to solve this issue ?
Thank you in advance
It's possible to have a pip command on your PATH that comes from a different Python installation than the python command. (Each entry script to a Python-based tool is bound to the Python installation that was used to install the package that provided it. This means that the pip command does not search PATH for a python installation.) If this pip comes up later on PATH than python, it would lead to behaviour that you describe.
This can happen, say, if you first install a Python 2.7 without pip, and then a Python 3.x with pip, if the installers prepend to PATH.
You can verify which version of Python pip is using and where it's installed by running pip -V.
The robust solution to this should be using a virtual environment that lets you tie the base python installation and libraries specific to your application alone with your project, as well as avoid cluttering your global site-packages, and prevent inadvertent compatibility issues from different versions of the same package being needed by different projects.
It seems that the current (as of late 2017) recommended virtual environment solution is Pipenv. A decent-looking introduction to virtual environments using Pipenv, by the author of Pipenv, can be found here.

Use pip with non-standard Python installation (non-root installation)?

I'm trying to get up and running with Python 3.5.2 and various packages on a server I work on, but don't have root privileges for. I installed Python to my home, and that seems to be working. I'm trying to set it up so I can install packages to that Python installation (ie ~/lib/python3.5/site-packages) via pip, but I cannot get it working.
Even after adding ~/lib/python3.5/site-packages to $PYTHONPATH, no luck.
Running pip install pandas, I get the error /usr/local/bin/python3.5: bad interpreter: No such file or directory , so it's still looking in the wrong spot. It should be looking at ~/bin/python3.5. Setting an --install-option="--prefix= argument doesn't change the problem.
Is this possible to do?
Try this:
pip3 install --user "library name"

Installing shapefile / shapelib not found via conda or pip

I am trying to read shapefiles to view suburbs in a city following this tutorial using windows 8, Anaconda and iPython.
I tried "conda install shapefile" and "pip install shapefile" in command prompt, both returning "Error: No packages found matching: shapefile".
Besides that I tried adding it manually following these links [1]How to import a module given the full path?
[2]Import python module NOT on path. However I am getting permission errors which suggests I am not importing them correctly anyway.
Any suggestions on how to proceed or best practices are appreciated.
try
pip install pyshp
in your cmd.
that is the name of you library as far as I can see, see https://pypi.python.org/pypi/pyshp
conda only works for these http://docs.continuum.io/anaconda/pkgs.html packages.
For the ones not in the list you need to use pip install. It can be confusing as the name of the library on pypi (this is where pip goes to download it) is often, but not always the same as the import name, so if conda and pip don't work, first try to google to make 100% sure that your library is not on pypi, because most respectable libraries are...

Categories

Resources