Python Libraries can't be detected - python

I installed some python libraries, but they can't be detected. In pycharm they are orange so excluted and Visual Studio Code says "Import "cv2" could not be resolved" if I want to include open cv. I also had 3 Versions of Python at first, but now I only have one left is that a problem?
Deleted old Versions of Python and Anaconda was the only thing that made the pip comand work again.
I looked up if everything is installed with "pip list".

You need to have the installed python in your path. The first interpreter it reaches in path will be used, if not just add it to your path
where.exe python
C:\dist\venvs\trk-fullstack-test\Scripts\python.exe
C:\dist\Python310\python.exe
C:\Users\mobj\AppData\Local\Microsoft\WindowsApps\python.exe
$ENV:PATH = "C:\dist\Python310;$ENV:PATH"
where.exe python
C:\dist\Python310\python.exe
C:\dist\venvs\trk-fullstack-test\Scripts\python.exe
C:\Users\mobj\AppData\Local\Microsoft\WindowsApps\python.exe
All modules installed with pip will follow the python interpreter used.
Recommend taking a look a https://docs.python.org/3/library/venv.html
to see how virtual environments are handled.

Related

Importing python package from conda environment in VSCode

enter image description here
Somebody please explain why I am not able to import package in VSCode even though I can do it in terminal both in VSCode and in system
Check out https://code.visualstudio.com/docs/python/environments
VSCode uses multiple python binaries. Each one has a seperate list of installed modules and packages. By default VSCode uses a custom Anaconda binary. When you invoke the python command, you are using a system wide install of Anaconda. You need to change the binary version of python VSCode is using, to point at the system-wide install, where you installed your modules

How to install Python, VSCode, and flake8 correctly on Win10

I greatly apologize for the newbie question. I am trying to correctly download and integrate a Python 3.7 installation with VSCode and using flake8 as a linter. I want to get set up for developing custom scripts for Blender. I'm on Win10 x64.
I downloaded the "python-3.7.8-amd64.exe" installation package, and installed it.
I made sure to select the checkbox that adds python to the PATH environment variable in the installer.
I pointed VSCode to the newly installed interpreter and was then prompted to install a linter.
Someone recommended flake8, so I selected that in VSCode and installed.
During the installation I get the following warnings:
WARNING: The script pyflakes.exe is installed in 'C:\Users\futur\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pycodestyle.exe is installed in 'C:\Users\futur\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script flake8.exe is installed in 'C:\Users\futur\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed flake8-3.8.3 importlib-metadata-1.7.0 mccabe-0.6.1 pycodestyle-2.6.0 pyflakes-2.2.0 zipp-3.1.0
I checked my environment variables and this is what shows up:
What I don't understand is why I have two Python directories in %APPDATA%. There is:
C:\Users\futur\AppData\Local\Programs\Python\Python37\Scripts
As well as:
C:\Users\futur\AppData\Roaming\Python\Python37\Scripts
flake8 installed in the Roaming folder, while my main Python installation is in
C:\Users\futur\AppData\Local\Programs\Python\Python37
So to conclude, these are my questions:
Did flake8 install in the wrong directory?
Should I add C:\Users\futur\AppData\Roaming\Python\Python37\Scripts to my USER PATH environment variable, or to my SYSTEM PATH environment variable?
Why are there two Python directories in %appdata%? (Roaming and Local)
Any guidance on how to properly set everything up correctly would be an ENORMOUS help and greatly appreciated.
Edit 1
Thank so much for all the answers. I want to emphasize that I would prefer to get this issue sorted out without just installing Anaconda.
Edit 2
I made some progress here. Instead of installing flake8 through VSCode, I just ran python -m pip install flake8 and everything seems good now.
According to your description, I successfully installed flake8.
I think there is a problem with your installation path of flake8.
Its default path will not be in roaming.
The default path will only have: C:\Users\futur\AppData\Local\Programs\Python\Python37\Scripts and C:\Users\futur\AppData\Local\Programs\Python\Python37;
The default is local, which usually stores executable programs and other large capacity files;
It is recommended that you could install python again and check the version and location of the pip (use "pip -- version").
You could use an environment tool to resolve all these.
Download anaconda and create a environment with your intended python version and install flake8 inside your conda env. VScode works well with anaconda env.
Download Anaconda it will auto-resolve all the problems which you are facing related to environment setup.
I don't think it is wrong. My new modules are also installed at same directory as yours.
For me, it only works when I add to SYSTEM PATH.
I also have Python in both Roaming and Local. But after checking my folders, it seem Local one is from my previous installation of Python.
As a side note, I also have to add env path for Python after installing Python installer. But, I remember clearly that in previous Python installers, I didn't have to add path manually. I wonder if there is any changes regarding path in new Python installer.
What I think happened is you used a global install of Python to install flake8 and the Python extension does a user install to help prevent you from breaking your Python installation (python -m pip install -u). So one path is to Python itself and the other is your user install of packages for a specific version of Python. That's why there's two separate locations.
The best way to manage this is to create a virtual environment and install into that (you don't need to switch to conda for isolation). That global install you did using python -m pip install flake8 is a bit risky as that could clash with other things you install in the future.

pipenv search python in old directory do not exist

I would to create new Python project which include pipenv for manage my packages.
But when I try to install package with it, it throw me I exception :
ValueError: Not a valid python path:
'C:/dev/Anaconda3/Scripts/python.exe'
I try pipenv command with 2 differents emulation terminal (Cmder and Terminus) which produce same result.
In old time a try Anaconda solutions for work with Python. But now I don't want use this and I uninstall Anaconda in my OS.
It seems that my OS keep old reference to this python executable into Anaconda in your PATH... But I display my 2 PATH variables OS (PATH system OS and PATH user) and nothing has this location path into your string.
The directory c:\dev\Anaconda3 doesn't exist !
I try to search uninstall Anaconda program in my tool application manager Windows but Anaconda is not diplayed in that listing. It seems to be good uninstalled.
I install correctly pipenv executable : pipenv --version
pipenv, version 2020.6.2
I install correctly python executable : python --version
Python 3.8.3
I added 3 differents PATH python for my OS PATH (system PATH and user PATH) :
C:\dev\python\Python38
C:\dev\python\Python38\Scripts\
C:\dev\python\Python38\Scripts\bin
Why I keep old reference to Anaconda program ?
Why many program search python in same old deleted path and PATH variable do not included this ?
How pipenv created his PATH environment variable ?
I had a Python2.7 instance giving me the same problem. I copy/pasted its python.exe into the Scripts folder. So it now found a real python.exe there. Once I did this it continued on happily. And now I was able to use the Python3.9 version i wanted it to use anyways.
It seems like the python searcher should be a little more tolerant and just ignore poorly formed python releases. There is an open ticket for this: https://github.com/pypa/pipenv/issues/4334
I had a similar error because of an incorrectly uninstalled Anaconda. To see if you have the same problem, go to System Settings > Add or remove programs, and check for anything unexpected matching "conda". Trying to uninstall it results in an error because the uninstall.exe file cannot be found.
Searching around, I saw a few posts that said to mess with regedit, but that's scary. Instead, I re-installed the version of Anaconda that I needed to uninstall (you can do that with https://repo.anaconda.com/archive/Anaconda3-2020.02-Windows-x86_64.exe, replacing 2020.02 with your Anaconda version), and then uninstalling it via the proper uninstaller via "Add or remove programs". After a restart, the phantom Anaconda python was gone
You need to delete the old path in the Windows Registry.
Hit win + r
regedit
find folders with (Anaconda3 or Miniconda3).
Probably two folders. Do not delete folders with the new path to Python.

How can I manage mutiple python in Ubuntu16.04?

  In my Ubuntu16.04, there are python 2 and python 3 default. In addition, i have installed anaconda too. I am sucked by the 'python' cmd. Every time i use pip or pip3 install, I don't know where the package install, python2 or python 3? And I use conda install to install anaconda package. I also use anaconda env to manage different virtual env. But I think it mix with my local Python 2 and 3.
  For example, in directory /usr/bin, I found many soft links like this:
   When i try 'python' cmd, it just confuse me!
   Why python3m are local, shouldn't it be anaconda? Why python3 are anaconda, shouldn't it be local? Then I found that if I use ./python2 or ./python3, I found it is correct now!
  So I know it is caused by environment variables. I echo $PATH, Found it like this: /home/kinny/.pyenv/shims:/home/kinny/.pyenv/bin:/home/kinny/anaconda3/bin:/home/kinny/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/ant/bin:/snap/bin:/opt/maven/bin:/usr/lib/jvm/java-8-oracle/bin
   I have used update-alternative --config python to configure default python, but it doesn't work! It sames mixed with each others.
   Now I just want to install tensorflow 0.11 in local python3, because in anaconda it is 0.10 version by default. So how can I change this. I just want to use python python3 and python3m represents python2.7 python3.5 and anaconda python respectively, How can I do that! use pip and pip3 for local python2 and python3 respectively!
I ran into a similiar problem when setting up PyCharm Edu to work with Anaconda. I found that I had several versions of Python installed and it was very hard to keep track of which version the IDE was referencing. My CS professor gave me the advice of simply removing the versions of Python I didn't frequent. I now just have Anaconda installed; and use the Anaconda Prompt as my Python console. I also rely on PyCharm's IPython for the developer console. However, if you still want differing versions of Python installed (say your doing QA testing for older devices); there is the really helpful command: which python. When entered into the python console or Anaconda Prompt: which python will display the directory associated with the currently executing Python Shell. This enables you to better keep track of to what particular python.exe the current window is referring to.
Follow up to the comments mentioning using virtualenv and virtualenvwrapper.
Here are the official docs and a good blog post to follow for getting started using virtualenv's is here:
https://virtualenv.pypa.io/en/stable/installation/
http://virtualenvwrapper.readthedocs.io/en/latest/install.html
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/
Also, once you are setup you can create virtualenv's specifying which python installation you want to use.
which python3
returns
/usr/bin/python3
Then create a virtualenv with that python path. Where example_env is the name of the virtualenv.
mkvirtualenv -p /usr/bin/python3 example_env
Then activate the virtualenv using virtualenvwrapper.
workon example_env
Finally, install tensorflow and other dependencies with pip.
pip install tensorflow
the which command is very useful for finding the path to the executable that is first in your path. Zsh also has the where command, which will show you all instances of the given executable that show up in your path. For managing different python versions, you have a lot of options. The easiest for most people tends to be anaconda, using conda environments. The installer will ask you to add some stuff to your .bashrc file, which will then make anaconda's binaries come first in your path. Anything else you run after the .bashrc gets sourced after that, will then use that first, including PyCharm. For graphical desktop apps to pick up the change, you may need to log out and back in again. If you only need one version each of python 2 and python 3, you can just use the ones available via apt. Depending on your Ubuntu version, Python 2 is definitely installed by default as it is used by many system utilities, including apt itself. Some newer versions may also install python 3 by default, but I do not remember for sure. Another option is to install the versions of python you need in an alternate location, such as /opt/python/<version> and then using environment-modules (installed via apt install environment-modules) or Lmod to control which versions are being used, but that may or may not be easy/convenient to use with a desktop application such as PyCharm.
for TensorFlow, 1.11 is available in anaconda, but I don't remember if it's in the default channel or not.

python 3.4.3 64bit a program required for this install could not be run

Trying to install Python 3.4.3 64-Bit and it gives me the following error:
'There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support or package vendor'
I have no bloody idea what this means so please help. Thanks in advance
I'm the admin on my computer and have all permissions
My windows is 64bit and is Windows 8.1
I had the same phenomenon occur when trying to clean up (uninstall various versions of Python and perform a clean install of 3.4.3) on my Windows 7 64-bit laptop. Unfortunately, I cannot tell you what "program required for this install to complete could not be run". Repeated attempts to "install for all users" produced the same "could not be run" (followed by a roll back of the install). Just before getting out Orca and diving into the innards of the MSI file, I attempted an "install just for me", and the install completed. I am, in fact, the only (human) user of this computer. There is another user account that was created during a cygwin setup, and access to some aspect of that user's profile/resources may have been the issue. If you are installing Python for your own use - and not as a "platform-wide" resource for other users as well - you might try installing "just for me".
For me the problem was that I had an older version of Python installed, that the MSI could not un-install. I had to manually remove it first.
This is how I resolved the problem on my Windows7 machine...
Open a command prompt and navigate to the location of the python.exe. (For me this was C:\Python34.)
Execute this command
python3 -B -m ensurepip._uninstall
Close the command prompt.
Using the python MSI file for the version of Python I had previously installed (yes, I went to the Python archive and downloaded the MSI for the old version), install Python again, but without the "pip" package. (Not sure if this is necessary, but it worked for me.)
Using the same Python MSI file, uninstall Python completely.
Using another MSI, for the version of Python you wish to install, you should now be able to perform a "clean" install.
I got the same error while uninstalling the python file from the control panel. It prompts
There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support or package vendor
I have solved this problem by installing the specific python-<version>.amd64.msi.
I then executed the MSI file. It asks for Change, repair, remove. First, click on Change radio button and complete execution. Later you can come to control panel and repair or uninstall the python file.
I had the same symptoms as OP. In my case, i had two separate installs, one of 2.7 and one of 3.4.3 and when i checked the PATH variable, there were 2 lines about PYTHONPATH pointing to the 2.7 version.
I removed the lines and then the repair funciton of the MSI did work. I uninstalled both versions and proceeded to reinstall.
Done :)
On a Win7 box:
Startup/ right click on Computer / Properties / Advanced system settings / Environment variables then check both sub-windows for paths related to python.
I had just the exact problem. But in mine case i've additionally removed the c:\python27 and c:\python36 directories and associated installers got stuck around Install/Uninstall and could not completely repair the installation (the /Scripts subdirectory has been missed and the python.exe reported an error about missed encodings module).
But i've found a solution for myself. Seems somehow the PYTHONHOME and PYTHONPATH environment variables (and may be PATH too) has been interfering with the Python installation process. But because i could not run Uninstall from the Windows Uninstall list in the Control Panel, then i did this:
Cleanup the PATH environment variable from all python path occurrences.
Remove PYTHONHOME and PYTHONPATH environment variables.
Restart Windows Explorer if environment variables (console command set PY must return the empty list) is not updated.
Run repair from (!) the python-3.4.4*.exe/python-2.7.11*.exe executables (download it if not done yet). Icons in the Windows Uninstall list in the Control Panel will reset into the original state for a repaired python installation.
Run the Uninstall from the same executables or from Windows Uninstall list in the Control Panel.
And it did the trick!
If you still needs the both versions of the python installation, then try install the older versions before the new versions. Seems it's important too.
Poking around, there is a temp file saying:
Error 1721. There is a problem with this Windows Installer package. A
program required for this install to complete could not be run.
Contact your support personnel or package vendor. Action: UpdatePip,
location: C:\Programs\PY272\python.exe, command: -m ensurepip -U
--default-pip
=== Logging stopped: 6/12/2015 13:26:17 ===
OK, so the missing "Voldemort" file (that which shall not be mentioned) is the ensurepip package. There is documentation for ensurepip at https://docs.python.org/2/library/ensurepip.html. I am still on 2.7, but it looks like this is a shared problem with Py 3.
The documentation says the ensurepip package is new in 2.7.9. My solution: install a version prior to 2.7.9 and then upgrade the files myself from an existing install. Done.

Categories