I'm trying to use the check-html flag with linkchecker. It gives an error that the tidy module is not installed. If I say tidy at a command line I can use it. I have MacPorts installed and have installed just about every option for libtidy or tidy that has to do with python. I'm thinking it has to do with a $PATH issue or something.
So if I am using python26 and I go into python and then say import tidy there are no errors and all is well. If I use python27 I get errors when I say import tidy. I'm assuming because I installed py26-utidylib py26-pytidylib. There were no py27s. I don't mind being in python26. So it appears if I am in python26 I should be able to run tidy.
But when I run linkchecker it says the tidy module is not installed. When I say which python it says my location is /opt/local/bin/python. Do I need to export the $PATH or $PYTHONPATH or something for it to work?
if you have 2 python compilers running, be sure you use the right one with the "python"-command.
you can see the used interpreter-version if you access the interactive-console with "python".
and you're right, the py26-...-library is for the python2.6 version. if there is no precompiled version you can always compile the library from the source for the required python-version. or at least, you can try.
but here you have to be sure to choose the right python-interpreter to execute the setup-process.
if you want the library for the 2.7-version you have to build it with 2.7-version.
you can also always check the used paths in which the current running python-interpreter is looking for modules, through the interactive python console:
python
>>> import sys
>>> sys.path
i assume you have the library installed for the wrong version, has import the wrong module ... or using it wrong :/.
maybe you could supply your code example!?
Related
I'm having ImportError: cannot import name 'Literal' from 'typing' error message when I try to use pip install. Anyone can help?
The problem is with the configuration of your environmental variables. The first thing, I'd suggest you do is uninstall all the unused versions of python. To my mind, the latest of python 3.x.x series is the best.
Steps:
The easiest way of accessing it is just to type environment variable in Windows 10 search bar. (Assuming you are using Windows 10)
Then follow these:
At the bottom half part of the subsequent window search for path:
If you double click that, look for python. Make sure you have such paths added there and you need to have a compatible version of python. Usually, your python bin directory is located in Program Files.
Here is the error
import numpy
Exception has occurred: ModuleNotFoundError
No module named 'numpy'
File "C:\path\to\file\32.py", line 1, in <module>
import numpy
Let me know how did you install the NumPy package; using pip or something else?
If you have multiple python versions, i.e. 2.x and 3.x at the same time, please make sure your interpreter for the 32.py file is the version that you installed NumPy on.
To possibly fix your problem, you should first try installing it and see if there are any errors. You should also check the version of Python you are running on Windows 10, because when you update Python it sometimes switches names between py and python
As you can see, the version of Python has changed between py and python so you should try changing that first.
If this does not work, you should try finding the directory for NumPy and adding it to the system PATH in your script. The installer usually shows you the location by doing the following:
import sys
sys.path.append("<insert numpy location here>")
import NumPy
This should manually force it into finding the package. If none of this works, please tell us and we should be able to find a different solution.
Happy Coding!
If you're using a code editor like PyCharm, you could install it by clicking on
file then settings then the project interpreter setting and install new module! You can search for the module and install.
Make sure that the python version that you want to use is a Windows Environmental Variable. You can test this by running this line in your command line.
> python --version
If you get some other python version that is not the one that you wish to use you can set the python version you want by finding where exactly your Python folder is located and go into settings and set the path as a new variable (I can leave a tutorial for you). If that is too much of a hassle, the Python installers can set the python that you will install as an environmental variable for you. (You could uninstall and reinstall and make sure that you allow it to make it an environmental variable.
After that you should be able to import whatever external packages you want using pip
for example:
pip install numpy
OK, I have an old Debian VM. Package managers are useless. No, I'm not going to update the OS.
I have the bzip2 lib and development headers installed correctly on my system (those actually came from a package).
I start with absolutely NO Python on the system. I removed everything manually. I downloaded the Python 2.7.5 source, and configured with ./configure --prefix=/usr. It configures fine. I run make, and it compiles fine. I try ./python -c "import bz2; print bz2.__doc__", it works, and says:
The python bz2 module provides a comprehensive interface for
the bz2 compression library. It implements a complete file
interface, one shot (de)compression functions, and types for
sequential (de)compression.
I then run make test and the whole test suite progresses fine, and notably the "test_bz2" test passes.
I then run make install, which installs my new Python binary into /usr/bin/ like I wanted.
I try /usr/bin/python -c "import bz2; print bz2.__doc__", and it fails with:
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named bz2
I've tried a bunch of different things, including building Python as --enable-shared and not, no luck. I've tried at least 10 times (each time totally cleaning out everything, running make distclean, etc.). No luck.
I tried: PYTHONPATH="/usr/lib/python2.7"; export PYTHONPATH. Still no luck.
HOWEVER, if I delete the symlink that make install creates for /usr/bin/python, and instead do: ln -s /path/to/my/python/compile/python python, NOW it magically works.
So, what the heck? Why is this Python binary I'm getting created only able to find stuff when the binary exists in the compile directory, and not when it's put into normal production install location? What am I missing?
I am root during the entire process, from configure to make to make install to trying to test the Python import call.
I have started from scratch again (this time compiling with --enable-shared btw), and verified that not only in the compile directory is there build/lib.linux-x86_64-2.7/bz2.so, but once I run make install, that file is put into /usr/lib/python2.7/lib-dynload/bz2.so.
I've tried to do some reading on lib-dynload, but haven't been able to determine if there's something else a Python program (like default configuration for the CLI or whatever) would need to be able to tell it to pull module imports from lib-dynload, or if there's some other place or option to tell the make install where it should be putting it instead of dynload.
Still I have no explanation why the /path/to/compilation/python binary can find and load bz2.so fine, but the /usr/bin/python binary can't find (or load) /usr/lib/python2.7/lib-dynload/bz2.so.
I thought maybe it was something to do with the fact that the installation doesn't create like a /usr/lib/python symlink to point at /usr/lib/python2.7 directory. But I created the symlink and still no go.
I am still lost here.
It would appear that a sort of non-answer answer was arrived at accidentally via a long string of Twitter conversation(s).
I've filed another Stack Overflow question here to ask WHY what we found was the solution to this problem: https://stackoverflow.com/questions/17662091/python-installation-prefix-not-being-persisted-in-config
For posterity sake, right now the solution is that I have to set the PYTHONHOME environment variable to /usr, and everything starts working. The puzzling part is that the documentation says PYTHONHOME should default to {prefix}, which I was clearly setting as default during configure to /usr. So why should I have to manually set it?
Running python-config --prefix reveals that the {prefix} default is in fact /usr/bin, NOT /usr like I specified, which leads to me needing to override the default back to the default, bizarrely.
I get this error when I try to use one of the py2exe samples with py2exe.
File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
I've installed py2exe with the installer, and I use python 2.6. I have downloaded the correct installer from the site (The python 2.6 one.)
My path is set to C:\Python26 and I can run normal python scripts from within the command prompt.
Any idea what to do?
Thanks.
Edit: I had python 3.1 installed first but removed it afterwards. Could that be the problem?
Sounds like something has installed Python 2.4.3 behind your back, and set that to be the default.
Short term, try running your script explicitly with Python 2.6 like this:
c:\Python26\python.exe setup.py ...
Long term, you need to check your system PATH (which it sounds like you've already done) and your file associations, like this:
C:\Users\rjh>assoc .py
.py=Python.File
C:\Users\rjh>ftype Python.File
Python.File="C:\Python26\python.exe" "%1" %*
Simply removing Python 2.4.3 might be a mistake, as presumably something on your system is relying on it. Changing the PATH and file associations to point to Python 2.6 probably won't break whatever thing that is, but I couldn't guarantee it.
Seems like you need to download proper py2exe distribution.
Check out if your c:\Python26\Lib\site-packages\ contains py2exe folder.
If you have any other versions of Python installed, it may be that another Python version is the default Python. Could this be the case? I believe the default Python installation is determined from a registry setting.
I had the exact same issue and I just managed to get it solved - so I thought I would share my solution.
It turned out that my installation of CollabNet SVN contained an old version of Python that interfered with my recent Python2.7 installation.
Replacing CollabNet SVN with VisualSVN (including a couple of reboots) did the trick. I know this is not a "pretty" solution, as it caused me to uninstall CollabNet SVN - a prettier solution might have been doing modifications to the PATH env. variable... However, I am now able to use py2exe :)
For the record, my very similar problem was caused by using a Cygwin prompt. Using as standard cmd.exe shell instead worked (given all paths and correctly installed versions of python).
This was because (stupid me) the Cygwin install had pulled down it's own version of /usr/bin/python. I equally fixed it by adding the Windows installed python location to the head of the Cygwin PATH=/cygdrive/c/Python27:$PATH.
You might need to install the py2exe module globally, perhaps you might have installed to a virtualenv. I had the same problem, installing the module globally fixed the problem
I'm just starting out with Python, and have found out that I can import various libraries. How do I find out what libraries exist on my Mac that I can import? How do I find out what functions they include?
I seem to remember using some web server type thing to browse through local help files, but I may have imagined that!
From the Python REPL (the command-line interpreter / Read-Eval-Print-Loop), type help("modules") to see a list of all your available libs.
Then to see functions within a module, do help("posix"), for example. If you haven't imported the library yet, you have to put quotes around the library's name.
For the web server, you can run the pydoc module that is included in the python distribution as a script:
python /path/to/pydoc.py -p 1234
where 1234 is the port you want the server to run at. You can then visit http://localhost:1234/ and browse the documentation.
Every standard python distribution has these libraries, which cover most of what you will need in a project.
In case you need to find out if a library exists at runtime, you do it like this
try:
import ObscureModule
except ImportError:
print "you need to install ObscureModule"
sys.exit(1) # or something like that
You can install another library: yolk.
yolk is a python package manager and will show you everything you have added via pypi. But it will also show you site-packages added through whatever local package manager you run.
just run the Python interpeter and type the command
import "lib_name"
if it gives an error, you don't have the lib installed...else you are good to go
On Leopard, depending on the python package you're using and the version number, the modules can be found in /Library/Python:
/Library/Python/2.5/site-packages
or in /Library/Frameworks
/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages
(it could also be 3.0 or whatever version)...
I guess it is quite the same with Tiger
Considering that in every operating system most of python's packages are installed using 'pip' (see pip documentation) you can also use the command 'pip freeze' on a terminal to print a list of all the packages you have installed through it.
Other tools like 'homebrew' for macOS (used when for some reason you can't install a package using pip) have similar commands, in this specific case 'brew list'.