Windows - Pycharm - Failed to install python packaging tools - python

In trying to install packages in Pycharm for the Python 3.6 interpreter, I get
Python packaging tools not found. *Install packaging tools*
And when I tried to install it gives me this error
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition
2017.3.1\helpers\packaging_tool.py", line 2, in <module>
import traceback
ModuleNotFoundError: No module named 'traceback'
I'm using Pycharm 2017.3.1 Community Edition

From pycharm,
goto settings -> project Interpreter
Click on + button on top right corner and you will get pop-up window of Available packages. Then search for packaging python package.
Then click on Install package to install the package.

I had a similar issue. In the end I had to remove an existing venv that was in the same location, delete multiple interpreters, then set up a new one.

For what it's worth..
I had a similar problem. Nothing answered here worked for me.
The problem started with Pycharm upgrade. The solution was to uninstall Pycharm, and obliterate what's in the Configuration directory (https://www.jetbrains.com/help/pycharm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#config-directory) along with alll jetbrains directories.
Reinstalled Phycharm 2022.1.1. Viola. Alas I have to reinstall all plugins I used in the old installation.
As far as I can tell, the problem - in my case at least - was the upgrade process.

The accepted answer wouldn't directly work if you have already created a Virtual environment.
That virtual environment would not be usable. So, go ahead and delete it.
Then, go and install the packaging module in the base python version, as shown in the accepted answer and then create a new virtual environment.
That new virtual environment can now be used.

Related

Trouble importing python packages using PyCharm

I've been trying to install simple packages for python such as numpy and pandas, and while I am able to install the package manually from the command line using pip as soon as I try to import it PyCharm can't find it. I have manually configured the path, with no luck.
PyCharm can also not find the packages I want to install itself and produces a connection timeout, this could be because I am working from a secure network.
Still pretty new to python and software dev in general, I apologise in advance if I'm being stupid, but no other similar threads are solving the issue.
I am operating on windows 7. The error I get is:
C:\Users\james.alexander\PycharmProjects\Test.py\venv1\Scripts\python.exe C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py
Traceback (most recent call last):
File "C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
I think PyCharm use a virtualenv, installing via pip won't work since it will install the package in your local env.
Check https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html
Try This:
Step 1: Ctrl+Alt+s
Step 2: Look for Project Interpreter Under Project
Step 3: Look for + In the right corner of prompt box.
Step 4: Search and select your required package. And Install button is just below.
First check the Project Interpreter in your pycharm.
File > Settings >Project >Project Interpreter
Check the version of python there (python2 or python3)
And check if you are using any virtual environment
And see what version python you have installed
For python3 you may have to use "pip3 install pkgname"
For python2 use "pip install pkgname"
In PyCharm, you can install modules from within the app. Simply access your preferences, then under 'Project Interpreter', you will find a table containing your installed modules. To install a new one, click the + symbol on the bottom - left, then search for the appropriate package, e.g. numpy. Once you've found it, simply click 'Install Package'. The module is now installed and ready to use!
EDIT: I've just seen that someone else has already posted this answer, sorry about that :)

ImportError: No module named twisted.persisted.styles

From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.

Installing python server for emacs-jedi

I am trying to install Jedi for emacs using marmalade package manager by following instructions here -- http://tkf.github.io/emacs-jedi/latest/. The package manger installs Jedi along with its dependencies. But I cannot install python server using:
M-x jedi:install-server
because that command is not available even after restarting emacs after jedi installation. The only available commands are:
Possible completions are:
jedi:ac-setup jedi:complete
jedi:dot-complete jedi:get-in-function-call
jedi:goto-definition jedi:goto-definition-next
jedi:goto-definition-pop-marker jedi:setup
jedi:show-doc jedi:show-jedi-version
jedi:start-dedicated-server jedi:stop-server
jedi:toggle-debug-server
My .emacs has the following:
(autoload 'jedi:setup "jedi" nil t)
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)
I am using emacs on Mac OS X.
At this current state when I open any python file (I use python 2.7), I see the following appear automatically in the minibuffer:
deferred error : (error Server may raise an error : Traceback (most recent call last):
File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 302, in <module>
main()
File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 298, in main
jedi_epc_server(**vars(ns))
File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 210, in jedi_epc_server
import_jedi()
File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 249, in import_jedi
import jedi
ImportError: No module named jedi
)
I tried installing jedi using other methods such as el-get and also manually but those seem to not even go this far. I see that the jedi commands available are even lesser than listed above.
Could someone help point out what I am missing?
Thanks.
Edit: The primary purpose I would like to use Jedi is to use auto-completion features for python programming although I believe Jedi has many powerful features. For such a purpose, is the python server essential or could one work around it? Eventually, of course, I'd like to take advantage of many more features in Jedi.
I managed to fix the problem thanks to help from Chris and syohex from emacs-jedi github. Credit goes to them in tracing this to Jedi version.
I am just linking the discussion on emacs-jedi issue #177 and pasting the workaround I found including other problems I encountered along the way.
I was using the Marmalade version which installs a much older version. So I uninstalled jedi and associated dependencies. I set my repository to MELPA and installed a much more recent version of jedi. This made the command
M-x jedi:install-server
available which wasn't the case earlier.
However, issuing that command gave an error
python-environment--make-with-runner: Program named "virtualenv" does not exist.
I made sure I added the location of virtualenv to PATH in my .bashrc.
So I looked up emacs-jedi issue #158 which suggests installing exec-path-from-shell. I installed it from MELPA and added the lines
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))
following instructions.
Restarting Emacs with the above lines gave an error:
Symbol's function definition is void: exec-path-from-shell-initialize
So I looked up Autoload issue #3 under exec-path-from-shell development (the link to this can be found in the link for emacs-jedi issue #177). Following one of the solutions, I restarted my computer, uninstalled and reinstalled exec-path-from-shell which magically did solve the problem that existed before the reboot.
Now I checked in emacs if virtualenv could be found using
M-! which virtualenv
It gave the right location.
Then I ran:
M-x jedi:install-server
which now seemed to run without trouble. The first time, there were messages about setting up a
default virtual environment under
/Users/XXX/.emacs.d/.python-environments
besides
Running: pip install --upgrade /Users/XXX/.emacs.d/elpa/jedi-20140321.1323/...Done
but in subsequent trials only the pip upgrade message was displayed.
Having seen that the server installed without trouble, I closed and restarted Emacs and opened a python script file. When I started editing, I got these messages in the minibuffers:
Error (jedi): Failed to start Jedi EPC server.
*** You may need to run "M-x jedi:install-server". ***
This could solve the problem especially if you haven't run the command yet
since Jedi.el installation or update and if the server complains about
Python module imports.
and
auto-complete error: (error Server may raise an error. Use "M-x epc:pop-to-last-server-process-buffer RET" to see full traceback:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/XXX/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py': [Errno 2] No such file or directory`
)
Thus, I realized that I have to issue the command:
M-x jedi:install-server
every time I start Emacs before opening any python file. Then I was finally able to see the auto-completion features being available during editing.
Though I can run the above command every time manually, I wanted to automate it from my .emacs whenever Emacs is launched. It turned out that I had the following line in my .emacs
(setq jedi:server-command (list "python" "/Users/XXX/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py"))
Upon removing this line in my .emacs, the problem went away and jedi is functional now.
Marmalade currently contains jedi version 0.1.2, but you're looking at documentation for version 0.2.0alpha2.
The documentation for 0.1.2 has different instructions:
package.el (Marmalade or MELPA)
You can install Jedi.el using package.el interface from Marmalade or MELPA. As package.el does not support installing non-elisp packages, you need to install Python part manually (see the next section).
And then in that next section, the imporant bit:
Install Jedi and python-epc by
make requirements (no need for root privileges) or
pip install -r requirements.txt if you want to determine where to install Python modules. You need root privileges (i.e., sudo) to install it in system directory.
You should be able to do make requirements from the ~/.emacs.d/elpa/jedi-0.1.2/ directory, but something like pip install epc jedi should work too.

Getting PyGame to import in Python interpreter after MacPorts install

I'm trying to start using the pygame module but I can't get it to run. I'm using Mountain Lion with Python 2.7 and MacPorts, but I also installed some science and math modules using Anaconda before I ever discovered and started using MacPorts. Note that my MacPorts was just updated before I started any of the following. I initially tried to just use:
sudo port install py27-game
which looked like it worked and set everything up without a problem. But, when I go into the Python interpreter from the command line and type:
import pygame
I get the response:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
So then I went in and did:
import sys
print sys.path
which gave:
['', '/Users/trav/anaconda/lib/python27.zip', '/Users/trav/anaconda/lib/python2.7',
'/Users/trav/anaconda/lib/python2.7/plat-darwin',
'/Users/trav/anaconda/lib/python2.7/plat-mac',
'/Users/trav/anaconda/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/trav/anaconda/lib/python2.7/lib-tk', '/Users/trav/anaconda/lib/python2.7/lib-
old', '/Users/trav/anaconda/lib/python2.7/lib-dynload',
'/Users/trav/anaconda/lib/python2.7/site-packages',
'/Users/trav/anaconda/lib/python2.7/site-packages/PIL',
'/Users/trav/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
So, I'm guessing that because I used the Anaconda set up when I initially put the NumPy, SciPy & Matplotlib setup on here that this has caused MacPorts to clash with this somehow in the path.
Should I just remove the Ananconda package? If so, how can I go about removing these dependancies when I do that?
Ok, so I figured out the problem, and it was my path. I went in and removed the anaconda package with:
rm -r ~/anaconda
Then, I used macports to basically reinstall the whole scipy stack with:
sudo port install py27-wxpython py27-numpy py27-matplotlib py27-scipy py27-ipython
This took some time to compile, and when it was finished I went in on the command line and used:
sudo port select --set python python27
After that I opened my interpreter and imported all my scientific computing needs without a problem and pygame, which I had installed earlier with macports. I hope this helps someone else in the future. ALSO: when you remove packages like anaconda, make sure and close your terminal and then re-open it or it will still try to use the dependancies of anaconda, which are no longer there. I had macports set up already so after removing anaconda the macports path became the default.
One last edit. In order to get all of this to run correctly and allow me to run the scripts from within emacs as well with all the imported modules I had to switch to aquamacs from my normal emacs editor in order for the correct path to be used from within the emacs environment , or I could have just run emacs from the terminal with /Application/Emacs.app/Contents/MacOS/Emacs.

ImportError: No module named Foundation

I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:
Here's what I have done to get PyObjC working in Snow Leopard:
Using the Finder, I went to Go > Connect to Server... and connected to http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/ as a guest.
I then made a folder called Xcode on my local system at ~Library/Application Support/Developer/Shared/Xcode/. (You may already have this folder, but I hadn't customized anything for myself yet).
I copied the File Templates folder from the red-bean server into my new Xcode folder.
Copied the Project Templates folder to some other place, for example, the Desktop.
Using the Terminal, navigated to the temporary Project Templates folder on my Desktop and ran this command to "build" the template.:
$ cd ~/Desktop/Project\ Templates/
$ ./project-tool.py -k -v --template ~/Desktop/Project\ Templates/Cocoa-Python\ Application/CocoaApp.xcodeproj/TemplateInfo.plist Cocoa-Python\ Application ~/Library/Application\ Support/Developer/Shared/Xcode/Project\ Templates/Cocoa-Python\ Application
When I try to run the line that starts with ./project-tool.py, I get the following error in Terminal:
Traceback (most recent call last):
File "./project-tool.py", line 22, in <module>
from Foundation import NSDictionary
ImportError: No module named Foundation
I am running Snow Leopard and have installed Xcode 3.2.1 and have read that this module should already be installed and working. I've read that you can test if the PyObjC modules are working by running >>> import objc in the Python command-line. When I run this, I get:
>>> import objc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named objc
Could anyone help me dispel this error? It seems like I should be able to do all of this automatically with my Snow Leopard installation, but I can't.
I had the same problem. Mine was caused I think by using homebrew to install my own Python to tinker with.
Because I was worried about mixing python versions, rather than creating the link as described above, I installed a new pyobjc using:
$ pip install pyobjc
For interest, from (http://pythonhosted.org/pyobjc/)
The PyObjC project aims to provide a bridge between the Python and Objective-C programming languages.
Okay, it turned out that, amending mjv's answer, I was able to get it working by typing
export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/PyObjC/"
before executing the ./project-tool.py line. I still find it ridiculous that I had to do this and if anyone can see why, I would be delighted to know.
Doing this also got the
>>> import objc
line working.
It's because PyObjC is there :
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
Edit :
I found how to make "import objc" work, just :
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/"
It will add all the directories to the python path (sys.path)
for python 2.7
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/"
One of two things:
Either the Fundation module doesn't exists
Or Python interpretor doesn't know when to find this file
Python looks for modules in the PythonPath
See this SO question for more details on how Python Path is created etc.
Run python -v to trace import statements, this work for interactive mode too.
I could access a Python installation with Foundation on my OSX by running /usr/bin/python file-to-run.py
remove your python or remove site-packages/Foundation | site-packages/foundation
pip3 install pyobjc
the name Foundation is in conflict with https://pypi.org/project/foundation/
I found the foundation folder in /usr/local/lib/python3.9/site-packages/ next to the AppKit folder. After renaming it to Foundation (with uppercase F), the import worked. The Filesystem is not case-sensitive but it seems some part of the import implementation is.
Saw it mentioned in another comment and I too ran into this problem due to installing Python via homebrew. My pyobjc installation wound up going to the Python homebrew installation, yet my pythonpath was linked to the Python that comes bundled with macOS, so there was this big disconnect and I had no luck getting pythonpath re-routed in .zshrc or .zprofile.
In the end, these steps resolved the issue:
brew uninstall python
pip3 install -U pyobjc

Categories