python cant find module in sys.path - python

I use the following command to install modules in home/.local since I dont have admin rights
pip install --install-option="--prefix=$HOME/.local" package_name
it is installed in my home dir and other cant run my script, so I move them to python lib/site-packages directory where others have access to. Then I add sys.path.insert(0, path_to_lib) in my script to import that module. This is how I install and use modules in my script and it always works fine. But when I did the same for a module "marrow.mailer", my script shows No module named marrow.mailer not sure why, the lib/site-packages folder does have that module. Please help me in finding solution for this. Thanks.

Related

Module import error even though sys.path shows the directory?

I am having trouble installing a package through its directory (not possible to install through pip, only folder available) on my mac.
I am using a python 2.7 environment on Conda and did the following after reading many posts and tutorials:
decompressed the file with the modules I need ("/Users/personal/python_files/PyOPC-0.1/PyOPC")
used the command conda develop "path/to/PyOPC" on the terminal
added the following line to the bottom of the ~/.bash_profile file: export PYTHONPATH="/path/to/PyOPC"
checked my sys.path through python2 -c "import sys; print('\n'.join(sys.path))" on the terminal
When I do the latter, I can see the path to PyOPC listed there, so I thought I wouldn't have problems importing any modules.
Nonetheless, when I run my code I get the following:
from basic import BasicXDAServer
ImportError: No module named basic
basic.py is a file inside the folder PyOPC/servers. If I move "basic" to the main PyOPC folder, I get a different import error referring to an import happening within basic.py...
Here is the complete directory I am referring to available on Github: https://github.com/ibh-systems/pyopc/tree/master/PyOPC
Is there a problem with the structure of the directory itself or did I do something wrong as I installed it. Thanks for the help.

Import does not look into pythonpath when importing personal modules

I have build my own package named "XXX" on my computer by setting a __init__.py file in the C:\path\to\module\XXX folder, which contain my python script. Then I added C:\path\to\module\XXX to my pythonpath manually. When I run python on a cmd prompt and try to import the module it fails. When I print sys.path, it contains C:\path\to\module\XXX. If I try to load some other personnal modules, the same problem occures but when I try to load module not of my own, installed with pip (i.e. numpy) it works perfectly. So my guess is that for some reason python is not looking into my pythonpath anymore to load module.
I am using anaconda with python 3.6.5 with a vitual environnement on windows 7. Python is installed with anaconda via conda-forge repo.
I have tested this issue with multiple approach, first by running the script below with Pycharm and then with Spider. Then I used anaconda prompt to run the commands manualy activating my virtual environnement first. Finally I ran the commands on a DOS prompt with python. Whatever the way, the results where the same. This error just occured after installing fbprohete in my virtual environnement. Before that I was able to import my modules. I tried to remove that module but the problem remains the same. A lot of mess append during the installation of fbprohet. After the installation I ran a conda clean command to clean the environnement but it didn't help. I suspect that something is corrupted now but I would like to avoid reinstalling everything. If you have an idea where to look, which module in particular should be corrupted, I will be glad to know more about it.
import sys
sys.path
['', 'C:\path\to\module\XXX', ...]
import XXX
ModuleNotFoundError: No module named 'XXX'
Whith the script above, I expect the module to be loaded without error since the path to the package is in the pythonpath and the __init__.py is in the folder C:\path\to\module\XXX
Thanks!
So it was a bit silly actually. I should have replaced C:\path\to\module\XXX by C:\path\to\module in the pythonpath because __ini__.py is in the C:\path\to\module\XXX folder. Thanks Giacomo Alzetta for your comment.

What should I set my pythonpath to

I downloaded a python module from online and want to use it in IDLE, but I keep getting an error message saying it's not found.
My python path is "/Library/Frameworks/Python.framework/Versions/2.7/bin". If I want to be able to run modules I downloaded from online into IDLE, what should I set my python path to to be able to do that?
I am running OsX 10.10.5
Create a directory somewhere under your home directory. Let's say it's ~/pylib. Copy the module to ~/pylib. Before running IDLE execute the command
export PYTHONPATH=~/pylib
You should now be able to import the module.
If a module you have downloaded was properly packaged, it should come with the installation routine. Conventionally, it is called setup.py. If you see this file, you can just do
python setup.py install
That should take care of most packages available online and you don't even need to figure out where it was installed to.
If you really need to check/set the paths, you can check the directories as reported by
import sys
sys.prefix
sys.exec_prefix
These are the paths that point to the directories where stuff is installed (prefix/lib).
If you are looking into custom or user installation (using --user flag), check this folder: userbase/lib/python<VERSION>/site-packages
More details in the documentation.

How to import python module

I'm working on a project for which I need to a module. I want to know how to import some other module in python that is not installed.
When I write
import xaut
It gives error no module named xaut.
I have xaut-0.4.5 that I downloaded from following link.
Please help me how to use it.
Well I think following will help
Extract your zip file
Open the command line (a linux terminal or cmd on windows). I am on linux so I have a terminal.
Now enter the directory that you have extracted.
In it is a directory "python" cd into it.
If you run the ls command (if on windows run dir) you will see that in this directory there is a script "setup.py". We need to execute it for installation.
Execute this script by giving command python setup.py install
This will hopefully install it and then you would be able to import it.
Basically you have only downloaded the package. To make a package work you also need to install it. So when you download a package always search for a setup.py file.
This is certainly a duplicate question. You can look up how to add a python module to the path in windows.
here is an example
How to add to the pythonpath in windows 7?

Python cannot find module even when path is appended to sys.path

Having some weird troubles installing python modules on my work computer (read: no admin/root rights), I'm using 2.7.5. I downloaded and unpacked the tarball and ran 'setup.py', but it had no effect: When I open the python shell, it can't find the module (this specific one is fuzzywuzzy). However, if I right click -> edit with IDLE the setup.py, and then run the shell from that file, it loads and works perfectly fine. Or, if I then open a new file from that shell, use the module and run it, it works fine. -__-
I've tried using:
import sys
sys.path.append('path here')
to append the location where the module is installed, but this doesn't help, nor does the path stay in the sys.path list when I close/reopen the shell.
This is actually driving me insane. Can anyone help? I'm relatively new to programming and python.
The best and easy way provided by python to install/uninstall packages is to use PIP.
use this
python -m pip install packagename==version
same way to uninstall
python -m pip uninstall packagename==version
if you are using windows you need to set path variable first usually python file will be in path C:\Python27 to set path variable
PATH=%PATH%;C:\Python27;

Categories

Resources