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?
Related
I'm a python beginner, and I'm following this tutorial for a webscraper https://hackernoon.com/building-a-web-scraper-from-start-to-finish-bb6b95388184
I'm on Windows 10, have setup a venv, activated and installed 2 modules using pip, and moved my script into the Scripts folder (from my understanding, this is the equivalent of the /bin/ folder on linux installations). The modules are bs4 and requests. I see both of these in the /Lib/ folder of my venv. I am using the Atom editor from atom.io, and the Scripts Package to run my script.
My script errors with a "module not found" error. Relevant snippet below:
scraper.py
from bs4 import BeautifulSoup
import requests
I get the error on both imports, indicating I've setup my project/imports incorrectly. I have no shebang line in my script, and suspect this is the problem.
My project structure looks like:
\ScraperProject
|-\ScrEnv
|-\Include
|-\Lib
|-\site-packages
|-\bs4
|-\requests
|-\Scripts
|-scraper.py
|-pyvenv.cfg
What is the proper way for me to import these modules into my script in a Windows environment?
with what python version are you working in the venv? Maybe try to uninstall those update pip and reinstall those again, making sure that you install them with pyhton3
My issue is related to running it from the Atom editor, something I hadn't considered before. It's calling the python executable from my PATH variable, and not the one in my venv. When running the script from the cmd window, and calling it with the python from my project folder/venv, it runs as expected. On to figuring out how to configure Atom to use the venv executables. Thank you very much for the interest and help!
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.
I have Python 2.7 installed at C:\Python27 and I have added the path C:\Python27\; to the environment variables and .py: to PATHEXT. I am able to launch Python.
I downloaded a folder google-python-exercises to my desktop, which contains a script hello.py.
Following the advice in the Google Developers course, I try to run the script by using python hello.py at the command prompt.
When I attempt this, I get the message: python: can't open file 'hello.py: [Errno 2] No such file or directory. What is wrong, and how am I supposed to fix it? I found that I can solve the problem by running cmd from the folder, but this seems like a temporary solution.
Python cannot access the files in the subdirectory unless a path to it provided. You can access files in any directory by providing the path. python C:\Python27\Projects\hello.py
I resolved this problem by navigating to C:\Python27\Scripts folder and then run file.py file instead of C:\Python27 folder
Options include:
Run the command from the folder where hello.py is located (this way, hello.py is already a relative path to the file). This is the solution that OP found.
Give a proper path to the hello.py file - either absolute (e.g. C:/Users/me/Desktop/google-python-exercises/hello.py) or relative (for example, google-python-exercises/hello.py, if the current working directory is the desktop).
Add a path to the folder (C:/Users/me/Desktop/google-python-exercises) to the PYTHONPATH environment variable, and run the code as a module (python -m hello).
In all cases, a path is being given directly - Python will not "search" for the file.
From your question, you are running python2.7 and Cygwin.
Python should be installed for windows, which from your question it seems it is. If "which python" prints out /usr/bin/python , then from the bash prompt you are running the cygwin version.
Set the Python Environmental variables appropriately
, for instance in my case:
PY_HOME=C:\opt\Python27
PYTHONPATH=C:\opt\Python27;c:\opt\Python27\Lib
In that case run cygwin setup and uninstall everything python.
After that run "which pydoc", if it shows
/usr/bin/pydoc
Replace /usr/bin/pydoc
with
#! /bin/bash
/cygdrive/c/WINDOWS/system32/cmd /c %PYTHONHOME%\Scripts\\pydoc.bat
Then add this to $PY_HOME/Scripts/pydoc.bat
rem wrapper for pydoc on Win32
#python c:\opt\Python27\Lib\pydoc.py %*
Now when you type in the cygwin bash prompt you should see:
$ pydoc
pydoc - the Python documentation tool
pydoc.py <name> ...
Show text documentation on something. <name>
may be the name of a Python keyword, topic,
function, module, or package, or a dotted
reference to a class or function within a
module or module in a package.
...
Try uninstalling Python and then install it again, but this time make sure that the option Add Python to Path is marked as checked during the installation process.
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;
I'm trying to run SnakeFood, to analyze a python project. I'm on a Windows machine and so far I've been able to figure out how to:
install Tortoise for Mercurial to download the SnakeFood code from the site
set the windows Path to accept python from the command prompt so I could do python setup.py install and got snakefood to go into my "site-packages" folder
Now, the documentation doesn't say anything else rather than:
sfood /path/to/my/project
I can't get this command to work. What am I missing?
Would this work?
python "DriveLetter:\path\to\sfood.py" "DriveLetter:\path\to\your\project"
Considering the documentation says "sfood /path/to/my/project" it most likely assumes a *nix environment. That leads me to the assumption that sfood probably has a shebang line.
On Windows you probably need to use "python sfood ". If "sfood" isn't in your PATH, you'll need to write the full path rather than just "sfood".
I was able to resolve this issue, on my Windows 7 machine with Python 2.7.3 installed, like so:
C:\> cd \path\to\snakefood\installation\folder
C:\path\to\snakefood\installation\folder> python setup.py install
...
C:\path\to\snakefood\installation\folder> cd C:\Python27\Scripts
C:\Python27\Scripts> python sfood \path\to\my\project
...