How change python module path? - python

I want to use the Scrapy Python module and because I have anaconda installed, scrapy is installed. However, I don't want to use the anaconda environment I want to use VSCode. I type "pip install scrapy" but it returns "Requirement already satisfied". How do I change the path way of this module because I can't run Scrapy in VSCode.
It gives me a "report missing imports" error but I already have it installed.
I already tried to uninstall and reinstall but that didn't work.

Python allows you to modify the module search path at runtime by modifying the sys.path variable. This allows you to store module files in any folder of your choice. Since the sys.path is a list, you can append a search-path to it.

Related

Python doesn't find any installed modules

My error
It does this for every module that I try to import?
I put everything that is needed in path.
You can install using command prompt. Open command prompt and type pip install numpy
apparently you are using anaconda make sure you are in the correct profile, if you are already I suggest you try using pycharm to create a virtual even, or even try to install any module locally

Importing in Python 3.6.0

Can't seem to get imports to work. I've installed using
pip install pyperclip
I can can confirm that it was successfully installed:
But then when attempt to confirm in in the Shell:
Is there another step to importing that I'm just missing?
Your problem is that pip is installing for the global (all users) version of python, and you're using a version of python installed for only your user c:\Users\bbarker\AppData\Local\Programs\Python\Python36. You'll want to either use the global install instead c:\program files (x86)\python36-32 or change your pip defaults as described here.
You'll notice the folder where pip told you where pyperclip was installed does not show up in sys.path. Therefore python does not know to search there for libraries. Those few file paths you did have in your sys.path are automatically generated defaults that are relative to the install directory of the particular instance of python you're currently using. If you use the instance in your \program files (x86)\ folder, the paths will be relative to that folder instead
tldr;
You have 2 instances of python installed, and you're installing libraries to one and using the other.

Module already installed but "ImportError"

I have installed the modules (for example: configobj, matplotlib, etc.) but when I try to import these modules in my Python script and try to run those scripts using Linux/Ubuntu 14 command prompt, it is giving "ImportError: No module named configobj".
But if I try to import the same module using ipython, it is not giving any issue.
Python version: 2.7.6 (when I checked with sys.version in ipython)
I have already installed anaconda. I don't know whether it can trigger any issues.
Tried:
Python error "ImportError: No module named"
I have tried changing $PYTHONPATH to point to anaconda lib/ directory as it was suggested in some post on stackoverflow only. Also, checked many questions here but unable to find any solution.
Followed some other links as well.
Thanks :)
Your new module needs to be in a path like
C:\Users\**SOMEUSER**\AppData\Local\Continuum\Anaconda2\Lib\site-packages
then you should install the module from cmd with
python setup.py install
(dont forget to cd to the modules directory in cmd..)
as there should be a "setup.py"-file in the modules directory.
You do not need your env-variable to look into Anaconda2\lib, who did you tell this?!
PYTHONPATH is for your python.exe to call python from cmd...

ImportError: "No modules named". But modules already installed in dist-packages

I am using python2.7 and trying to import modules such as psycopg2. But I get the following error when I try to import the module:
import psycopg2
ImportError: No module named psycopg2
When I try pip to install the module it gives me the following message:
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Can anyone please tell me what I am doing wrong?
Is the module installed in your PYTHONPATH?
You can verify running this command line:
python -c "import sys; print '/usr/local/lib/python2.7/dist-packages' in sys.path"
Try to put psycopg2 module (or package, i don't know psycopg2) in the same directory of your script, and try to import it. Import searches first in the current directory.
import sys
print sys.path
Should display which are the search directories for the python interpreter, in order from the first to the last. The first is always the current directory, then there are the directories in PYTHONPATH and then python setup-dependent directories.
See:
https://docs.python.org/2.7/tutorial/modules.html#the-module-search-path
You can edit sys.path in order to reach your module, or put the module in one of its directories.
Check where you installed the package, for me it was into the python 32 bit folder c:\program files (x86)\python37-32\lib\site-packages.
The problem I was running VsCode in x64 bit mode and the packages live in the x86 folder.
See here how you can change the interpreter you're using - in my case - I needed to set it to Python 3.7.4(x86) 32 bit (image off internet):
Make sure that your PYTHONPATH and/or PYTHONHOME variables are set properly. These environment/command line variables get searched when Python looks for modules to import. So, if the module is properly installed, you should make sure a reference that location is in one of those variables.
Check out these links PYTHONHOME and PYTHONPATH
Make sure that you are running your program in same python version in which you have installed package
For example,you have installed package in python3 and you are running the code with python2..that might be the case to give the error

python says “no module named nest” when it is in the $PATH

import nest gives the 'no module named nest' error when it is in the $PATH, which means that there is a /opt/nest/lib/python2.7/site-packages: in my system $PATH. At this location there is a directory named nest and the structure inside the nest directory is looks like:
, where there is an __init__.py obviously. So why can't python find nest?
more information:
I am sure that I installed nest with python2.7, and run it with the same python2.7.
According to the docs, there are several ways to install python packages:
using distutils - running python setup.py install installs the package to site-packages of your current distribution;
passing --user to setup.py install installs module to ~/.local/lib/python2.7/site-packages on Unix, and this directory in under normal conditions always included in sys.path;
passing --home=$HOME to setup.py install installs module under $HOME directory. This directory should be included to sys.path explicitly;
modifying python search path:
you can do either
import sys
sys.path.append('/opt/nest/lib/python2.7/site-packages')
in the beginning of your script; or your can add
PYTHONPATH=/opt/nest/lib/python2.7/site-packages
export PYTHONPATH
in the end of your ~/.bash_profile file.
UPDATE:
Just tried to install nest and found that it comes in two flavours - 32bit (under /opt/nest/lib) and 64bit (under /opt/nest/lib64). You might have tried to use 32-bit python package with 64-bit python distribution. Try to change the string in ./zshrc to
PYTHONPATH=/opt/nest/lib64/python2.7/site-packages and see if it works. It works for me at least.
To set relevant environment variables correctly, NEST installs have a config that you can just source
source <installpath>/bin/nest_vars.sh
That sets the PATH and PYTHONPATH correctly and points NEST to the right directories for dynamically loaded content (modules, help pages, …)

Categories

Resources