Finding out the Python used to install the current package? [duplicate] - python

This question already has answers here:
Find full path of the Python interpreter?
(3 answers)
Closed 6 years ago.
Is there a way to programmatically find which Python version was used to install the current package?
If you have a package called mypackage and it has in its setup.py something like:
scripts = ["myscript.py"]
suppose install the package with easy_install or pip using a particular Python version, Python 2.x:
/usr/local/bin/python2.x setup.py install
Then in myscript.py, how can you find out that it was /usr/local/bin/python2.x that was used to install mypackage from myscript.py as opposed to some other Python version available on the system? I'd like to know the full path and not just the version info because I want to use /usr/local/bin/python2.x in my script.

Use sys.executable.
A string giving the absolute path of the executable binary for the
Python interpreter, on systems where this makes sense. If Python is
unable to retrieve the real path to its executable, sys.executable
will be an empty string or None.

Have a look at sys.version or sys.version_info.

Related

Why python didn't see nltk module? [duplicate]

This question already has answers here:
How do I use installed packages in PyCharm?
(14 answers)
Closed 4 months ago.
I cant run my programm because nltk module is missing but i just intstalled it and it just right here in the folder
I tried to reinstall my python, and tried to change python interpreter but nothing worked
How have you actually installed nltk?
You can check if it's actually installed with pip freeze.
What might be happening here is that you could have another version of python installed, so make sure that you actually call the same interpreter for checking and installing with pip, in your case E:/pythonProject1/Scripts/python.exe -m pip freeze and E:/pythonProject1/Scripts/python.exe -m pip install nltk

Installed Python 3.8.5, but my terminal still detects Python 2.7 (Catalina on mac) [duplicate]

This question already has answers here:
Dealing with multiple Python versions and PIP?
(28 answers)
Closed 2 years ago.
I was trying to install biopython with pip, but I get an error saying Python 3.6 or later is required, but 2.7 was detected. Weirdly though, when I look for my python version, it indicates I have 3.8.5 installed.
Should I move directories somehow? I just upgraded my Catalina version and did a thorough cleanup on my mac. Maybe I accidentally moved a file or two?
here's what my terminal looks like
Thank you!!!!!
You have to deconflict pip and make sure you're using the right one. There's a good answer on another Stack Overflow question.
The bottom line is, you might try:
which -a pip
to see all pip installations in your path.
You can use a specific version of pip like this:
python3 -m pip install something
or, I think you can also do:
pip3.6 install something

Using a python package [duplicate]

This question already has answers here:
How to install Python packages from the tar.gz file without using pip install
(7 answers)
Closed 5 years ago.
I have downloaded the tar file of the Python geohash package
I import functions from this package to use them inside my python programs. It works completely fine, but only inside its own folder, where it is extracted.
If I intend to use this package in any other location, it doesn't simply import that package.
What should I do if I want to use it anywhere in my system ?
(the package is only available through this tarfile, not through pip/sudo apt-get)
Simply untar/unzip the file and make sure you have setup.py visible. From you command prompt in windows or linux. Go to the dir of the package which you just unzipped/untarred and dir/ls to make sure that setup.py is there and then do the following:
If you are using virtualenv:
/path-to-your-venv/venv/bin/python setup.py install
If you are not using virtualenv
python setup.py install

Python, Django with PyCharm. Message error: "No module named M2Crypto" How resolve? [duplicate]

This question already has answers here:
How do I use installed packages in PyCharm?
(14 answers)
Why isn't PyCharm's autocomplete working for libraries I install?
(2 answers)
Closed 4 years ago.
I received this message: "No module named M2Crypto"
I have already install M2Crypto with the command "pip install M2Crypto" and when I re-run it, I got the message: "Requirement already satisfied"
What's the problem with M2Crypto?
Thanks
ps:
I use Linux: 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux, Pycharm and Python2.7 (/usr/bin/python2.7)
Maybe some interpreter option in PyCharm configuration for running the project?
First of all, verify that the version of pip is in line with your interpreter.
So for python2.7,
pip --version
should print something like
pip 6.0.8 from /usr/local/lib/python2.7/dist-packages (python 2.7)
depending on how you've installed it. The important part is in the end, where your interpreter ("python 2.7") should be shown.
Once you're sure to have the right pip-version, ensure your package is correctly installed. It should usually be installed in the directory printed out previously by pip (e.g. /usr/local/lib/python2.7/dist-packages/).
Assume you've already done this, what else can go wrong to make your interpreter not finding the 'M2Crypto' package?
python uses the PYTHONPATH environment variable for module lookups. So, there's the possibility, that your PYTHONPATH variable has been changed. Try running your program by adding the above-mentioned path to PYTHONPATH and either exporting it before running your webserver:
export PYTHONPATH=/usr/local/lib/python2.7/dist-packages/:$PYTHONPATH
# run your server here
or by prepending the same variable to your command:
PYTHONPATH=/usr/local/lib/python2.7/dist-packages/:$PYTHONPATH python <run-stuff-here>
This should make your program find the M2Crypto module.

How do I install modules in Python on Windows? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Installing modules in Python on Windows
The instructions in the documentation aren't helping. How do I install a module in Python?
If there is setup.py source file in module directory, run windows command line utility, change current directory to module directory and write
python setup.py install
make sure that python bin directory is in your system path variable
The same as everywhere, use easy_install. (Still it is somewhat more difficult to use under Windows because the cmd shell is far less powerful than bash)
You could try using pip

Categories

Resources